【问题标题】:Why time_since_epoch() from a std::filesystem::file_time_type is negative?为什么 std::filesystem::file_time_type 中的 time_since_epoch() 为负数?
【发布时间】:2021-04-17 19:09:56
【问题描述】:

为什么下面的代码输出的是负数?

coliru link 自己查看和编译代码。

#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

【问题讨论】:

    标签: c++ time filesystems chrono


    【解决方案1】:

    libstdc++ 的 std::filesystem::file_time_type::clock() 的纪元似乎是 2174-01-01 00:00:00 UTC,因此当前日期的负数并不意外。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      相关资源
      最近更新 更多