fork download
  1. #include <chrono>
  2. #include <cstring>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. using Timestamp = std::chrono::system_clock::time_point;
  7.  
  8.  
  9. int main() {
  10. char data[1000] = {};
  11. // check "garbage" values for being C strings or timestamps.
  12. auto check_garbage_value = [&](uint64_t value) {
  13. auto * v = ::new (&data[0]) uint64_t{value};
  14. data[sizeof(uint64_t)] = '\0';
  15. auto t = std::chrono::system_clock::to_time_t(Timestamp(Timestamp::duration(value)));
  16. auto tm = *::gmtime(&t);
  17. cout << *v << " -> '" << (const char *)v << "' or "
  18. << tm.tm_year + 1900 << "-" << tm.tm_mon + 1 << "-" << tm.tm_mday
  19. << endl;
  20. };
  21.  
  22. check_garbage_value(1784067974984445981ull);
  23. check_garbage_value(7310595060589862666ull);
  24.  
  25. cout << endl;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1784067974984445981 -> '0�^H�' or 2026-7-14
7310595060589862666 -> '
/syste' or 2201-8-31