C++ 64 位时间戳到 32 位 time_t

标签 c++ 32bit-64bit

我想将 64 位时间戳(美国)转换为日期字符串,以便通过系统命令“date”设置系统日期。我发现/实现了这个解决方案:

char loc_ach_buf[25];
uint64_t loc_ui64_TimeStamp_us;
time_t loc_t_TimeStamp_s;
...         
loc_t_TimeStamp_s = loc_ui64_TimeStamp_us / 1000000;
strftime(loc_ach_buf, sizeof(loc_ach_buf), "date %Y%m%d%H%M.%S", gmtime(&loc_t_TimeStamp_s));
system(loc_ach_buf);

这工作正常,但我的问题是,time_t 在我的系统上是一个 32 位值,所以会有问题 Year 2038 problem .任何想法如何解决这个问题?或者是否有 strftime 的替代方案。

最佳答案

为什么要使用系统命令'date'?使用 SetSystemTime API 调用。

关于C++ 64 位时间戳到 32 位 time_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12597618/

相关文章:

c++ - Const 正确性 - 如何在 C++ 中访问 vector vector 的元素?

C++ 比较 const char* 和 std::string

c++ - 如何以标准方式从未对齐的内存中获取值?

iOS 8 setValuesForKeysWithDictionary 在 iPhone 5/iPhone 4s 上失败

c++ - 在 64 位机器 (c/c++) 上编程有什么需要注意的地方吗?

c++ - 我可以用 bind1st/2nd 替换 boost::bind 吗?

c - 将 Fortran/C 程序从 32 位升级到多体系结构

C 字符串初始化。可能的麻烦

reflection - 使用反射从 Visual Studio(32 位)中的 T4 模板中分析 64 位 DLL

c++ - 使用模板将std::shared_ptr <Derived>上载到std::shared_ptr <Base>