all Python 3timefunction
time.gmtime()
time conversion
Converts seconds since the epoch to a struct_time in UTC; without an argument it uses the current moment.
Syntax
time.gmtime([secs])
The result does not depend on the machine's time zone, so gmtime(0) is 1 January 1970, 00:00 everywhere. Fractions of a second are dropped. The inverse is calendar.timegm(), not mktime(): mktime() treats the tuple as local time and shifts it by the zone offset. For date work, datetime.fromtimestamp(ts, tz=timezone.utc) is more convenient.
Examples
import time
t = time.gmtime(0)
print(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour) # → 1970 1 1 0
print(time.gmtime(1.9).tm_sec) # → 1
See also
Open in the full glossarydocs.python.orgReport an inaccuracy