I am using Python 3.6.0 on Windows 10 x64.
I just found that in time.ctime(seconds)
, seconds
parameter has an implicit maximum value, which
The time
documentation doesn't mention any limits, but the datetime documentation does:
fromtimestamp()
may raiseOverflowError
, if the timestamp is out of the range of values supported by the platform Clocaltime()
orgmtime()
functions, andOSError
onlocaltime()
orgmtime()
failure.[...]
Naive
datetime
instances are assumed to represent local time and this method relies on the platform Cmktime()
function to perform the conversion. Sincedatetime
supports wider range of values thanmktime()
on many platforms, this method may raiseOverflowError
for times far in the past or far in the future.
Then we head over to the Windows documentation:
_localtime64
, which uses the__time64_t
structure, allows dates to be expressed up through 23:59:59, December 31, 3000, coordinated universal time (UTC), whereas_localtime32
represents dates through 23:59:59 January 18, 2038, UTC.
localtime
is an inline function which evaluates to_localtime64
, andtime_t
is equivalent to__time64_t
. If you need to force the compiler to interprettime_t
as the old 32-bittime_t
, you can define_USE_32BIT_TIME_T
. Doing this will causelocaltime
to evaluate to_localtime32
. This is not recommended because your application may fail after January 18, 2038, and it is not allowed on 64-bit platforms.
All the time-related functions (including ctime
) work the same way. So the max date you can reliably convert between timestamps on Windows 10 is 3000-12-31T23:59:59Z.
Trying to get a platform-independent max timestamp is difficult.