64位Unix时间戳转换

64位Unix时间戳转换

问题描述:

对于32位系统,是否有C ++实现的64位Unix时间戳转换?我需要将 struct tm 转换为64位整数,反之亦然,包括leap年,时区和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 的较新的库,该库还实现了 mktime64 localtime64_r :

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

https://github.com/evalEmpire/y2038