开发者

epoch timestamp converter with millennia range, python

开发者 https://www.devze.com 2022-12-14 21:13 出处:网络
is there an epoch time converter that can deal with millennia? time.gmtime(1000 * 365 * 24 * 60 * 60) throws

is there an epoch time converter that can deal with millennia?

time.gmtime(1000 * 365 * 24 * 60 * 60)

throws

Val开发者_Go百科ueError: timestamp out of range for platform time_t


Yes, at least on Windows (using Windows 7 here). What platform are you using?

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
>>> time.gmtime(1000*365*24*60*60)
time.struct_time(tm_year=2969, tm_mon=5, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=123, tm_isdst=0)

Also, even on Linux you should be able to do some processing of dates well beyond 2038 using the datetime module. The docs say MAXYEAR is 9999 for that module:

>>> dt = datetime.datetime.now().replace(year=1000+1971)
>>> dt
datetime.datetime(2971, 12, 29, 11, 43, 20, 727000)
>>> dt.timetuple()
time.struct_time(tm_year=2971, tm_mon=12, tm_mday=29, tm_hour=11, tm_min=41, tm_sec=16, tm_wday=6, tm_yday=363, tm_isdst=-1)

Of course, that last call probably won't work on Linux if the time.gmtime() call is failing, but since you haven't really said what you want to do with the date maybe this is sufficient for now.

0

精彩评论

暂无评论...
验证码 换一张
取 消