64 位 Unix 时间戳转换 [英] 64-bit Unix timestamp conversion

查看:47
本文介绍了64 位 Unix 时间戳转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有针对 32 位系统的 64 位 Unix 时间戳转换的 C++ 实现?我需要将 struct tm 转换为 64 位整数,反之亦然,包括闰年、时区、UTC.还需要它的便携性,至少对于 GNU/Linux 和 Windows.

Is there any C++ implementation of 64-bit Unix timestamp conversions for 32-bit systems? I need to convert struct tm to 64-bit integer and vice versa, including leap years, time zones, UTC. Also need it portable, at least for GNU/Linux and Windows.

推荐答案

您需要:

typedef long long time64_t; 
time64_t mktime64(struct tm *t); 
struct tm* localtime64_r(const time64_t* t, struct tm* p);

最初(2011 年)此答案包含指向 2038bug.com 的链接,可以在其中下载包含上述函数的小型 pivotal_gmtime_r 库.当时该库已从 2038bug.com 中删除,链接已损坏并被版主从答案中删除.似乎现在可以在此处找到 pivotal_gmtime_r 代码:

Originally (in 2011) this answer contained links to 2038bug.com where it was possible to download the small pivotal_gmtime_r library, containing the mentioned functions. The library has been removed from 2038bug.com back then, the links became broken and were removed from the answer by a moderator. Seems like that pivotal_gmtime_r code can now be found here:

https://github.com/franklin373/mortage/tree/master/time_pivotal

此外,我还发现了另一个更新的库,名为 y2038,它也实现了 mktime64localtime64_r:

Also, I've found another, more recent library, called y2038, that also implements mktime64 and localtime64_r:

https://github.com/evalEmpire/y2038

这篇关于64 位 Unix 时间戳转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆