classmethod datetime.utcfromtimestamp(timestamp)
Return the UTC datetime
corresponding to the POSIX timestamp, with tzinfo
None
. This may raise OverflowError
, if the timestamp is out of the range of values supported by the platform C gmtime()
function, and OSError
on gmtime()
failure. It’s common for this to be restricted to years in 1970 through 2038.
To get an aware datetime
object, call fromtimestamp()
:
datetime.fromtimestamp(timestamp, timezone.utc)
On the POSIX compliant platforms, it is equivalent to the following expression:
datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp)
except the latter formula always supports the full years range: between MINYEAR
and MAXYEAR
inclusive.
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 gmtime()
function. Raise OSError
instead of ValueError
on gmtime()
failure.
Please login to continue.