classmethod datetime.fromtimestamp(timestamp, tz=None)
Return the local date and time corresponding to the POSIX timestamp, such as is returned by time.time()
. If optional argument tz is None
or not specified, the timestamp is converted to the platform’s local date and time, and the returned datetime
object is naive.
If tz is not None
, it must be an instance of a tzinfo
subclass, and the timestamp is converted to tz’s time zone. In this case the result is equivalent to tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz))
.
fromtimestamp()
may raise OverflowError
, if the timestamp is out of the range of values supported by the platform C localtime()
or gmtime()
functions, and OSError
on localtime()
or gmtime()
failure. It’s common for this to be restricted to years in 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp()
, and then it’s possible to have two timestamps differing by a second that yield identical datetime
objects. See also utcfromtimestamp()
.
Changed in version 3.3: Raise OverflowError
instead of ValueError
if the timestamp is out of the range of values supported by the platform C localtime()
or gmtime()
functions. Raise OSError
instead of ValueError
on localtime()
or gmtime()
failure.
Please login to continue.