简体   繁体   中英

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. This works fine but this limits my code to input between 1970 and 2038. I would now like to make my code more general.

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)?

(I'm adapting the code to deal with historical events hence it would be nice if it could also deal with dates in BC ....)

Yes, the y2038 project is reimplementing time.h to be 2038 safe. So far gmtime() , localtime() , mktime() and gmtime() are done and well tested. Those were the hard bits. It spans about 300 billion years in either direction.

There's a public domain implementation used in SQLite: documentation , source

I've also found the Calendar FAQ useful; this page pops up early on Google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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