如何为 1970 年 1 月 1 日 00:00:00 创建一个 std::chrono::time_point?
How can I create an std::chrono::time_point for 1 Jan 1970 00:00:00?
是否有可移植的符合标准的方法来为 1970 年 1 月 1 日 00:00:00 创建 std::chrono::time_point?这必须是线程安全的。因此,解决方案应该避免像 std::gmtime()
和 std::localtime()
这样没有线程安全保证的函数。
这不是 Convert std::chrono::time_point to unix timestamp 的副本,因为我要的是 可移植 解决方案 线程安全 .那里的问题也没有要求,答案也没有提供这种保证。
在实践中,std::chrono::system_clock::from_time_t(0)
将 return 您想要的值。
原则上我看不出你想要什么。
作为替代方案,在多个线程启动之前计算一次该值(在启动时)运行。
是否有可移植的符合标准的方法来为 1970 年 1 月 1 日 00:00:00 创建 std::chrono::time_point?这必须是线程安全的。因此,解决方案应该避免像 std::gmtime()
和 std::localtime()
这样没有线程安全保证的函数。
这不是 Convert std::chrono::time_point to unix timestamp 的副本,因为我要的是 可移植 解决方案 线程安全 .那里的问题也没有要求,答案也没有提供这种保证。
在实践中,std::chrono::system_clock::from_time_t(0)
将 return 您想要的值。
原则上我看不出你想要什么。
作为替代方案,在多个线程启动之前计算一次该值(在启动时)运行。