Python Glossary Русский

all Python 3timefunction

time.localtime()

time conversion

Converts seconds since the epoch to a struct_time in the machine's local time zone; without an argument it gives the current local time.

Syntax

time.localtime([secs])

The same timestamp gives different hours on different machines: the zone comes from OS settings or the TZ variable, so on a UTC server 'local' time is not Moscow time at all. tm_isdst=1 means daylight saving time is in effect. Dates outside the platform range raise OverflowError or OSError — on Windows already for negative values.

Examples

import time
now = time.localtime()
print(now.tm_hour)  # → ? 14 — зависит от момента и пояса
print(time.localtime(0).tm_year in (1969, 1970))  # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy