简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM