all Python 3timeterm
time.struct_time
time conversion
The type of a broken-down time: a named tuple of nine fields (year, month, day, hour…) returned by gmtime(), localtime() and strptime().
Syntax
t = time.gmtime(0); t.tm_year, t[0]
Fields are available both by index and by name (t[0] and t.tm_year), but the object is immutable: assignment raises AttributeError, so build a new value instead. The month is 1..12 (C used 0..11), and tm_wday counts Monday as zero, like date.weekday(). tm_isdst=-1 means 'DST unknown' — pass it that way to mktime(). There is no date arithmetic here: for 'plus 3 days' use datetime and timedelta.
Examples
import time
t = time.gmtime(0)
print(t.tm_year, t[0], t.tm_mon, t.tm_wday) # → 1970 1970 1 3
try:
t.tm_year = 2000
except AttributeError as e:
print(e) # → readonly attribute
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy