Why time_since_epoch() from a std::filesystem::file_time_type is negative?

Viewed 284

Why does the following code output a negative number?

coliru link to see and compile the code yourself.

#include <chrono>
#include <filesystem>
#include <iostream>

int main()
{
  std::cout << "Now: "
            << std::filesystem::file_time_type::clock().now().time_since_epoch().count()
            << "\n";
  return 0;
}
Output:

Now: -4818978774392359625
1 Answers

The epoch for libstdc++'s std::filesystem::file_time_type::clock() appears to be 2174-01-01 00:00:00 UTC therefore a negative count for current dates is not unexpected.

Related