为什么来自 std::filesystem::file_time_type 的 time_since_epoch() 是负数?

问题描述

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

coliru link 自己查看和编译代码

var ticketList = ctx.Tickets
                        .sqlQuery("Select * from Tickets where Id=1")
                        .ToList<Ticket>();
#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;
}

解决方法

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