简体   繁体   English

time.h drop-in replacement:time_t表示ANSI-C或C99中的值(年<1970)和(年> 2038)

[英]time.h drop-in replacement : time_t for values (year < 1970) and (year > 2038) in ANSI-C or C99

I have a piece of code in ANSI C which uses the time.h library and time_h structures to (amongst other date-related calculations) work out the interval between two given dates. 我在ANSI C中有一段代码,它使用time.h库和time_h结构(以及其他与日期相关的计算)计算出两个给定日期之间的间隔。 This works fine but this limits my code to input between 1970 and 2038. I would now like to make my code more general. 这很好但是这限制了我在1970年到2038年之间输入的代码。我现在想让我的代码更通用。

Is there a common C library (ANSI or C99 standard) which implements date calculations on ranges larger than time.h, on a granularity of 1 day (ie I need to-the-day resolution but hour resolution is not necessary)? 是否有一个通用的C库(ANSI或C99标准),它在大于time.h的范围内实现日期计算,粒度为1天(即我需要当天的分辨率,但不需要小时分辨率)?

(I'm adapting the code to deal with historical events hence it would be nice if it could also deal with dates in BC ....) (我正在调整代码来处理历史事件,因此如果它也能处理BC中的日期会很好....)

Yes, the y2038 project is reimplementing time.h to be 2038 safe. 是的, y2038项目重新实现time.h为2038安全。 So far gmtime() , localtime() , mktime() and gmtime() are done and well tested. 到目前为止, gmtime()localtime()mktime()gmtime()已经完成并经过了充分测试。 Those were the hard bits. 那些是硬点。 It spans about 300 billion years in either direction. 它向两个方向延伸了大约3000亿年。

There's a public domain implementation used in SQLite: documentation , source SQLite中使用了一个公共域实现: 文档源代码

I've also found the Calendar FAQ useful; 我还发现日历常见问题解答很有用; this page pops up early on Google. 页面在Google上提前弹出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM