Python Glossary Русский

all Python 3Linux · macOStimefunction

time.tzset()

time zone

Re-reads the TZ environment variable and recomputes local-time rules and tzname/timezone. Unix only: Linux and macOS.

Syntax

os.environ['TZ'] = '...'; time.tzset()

Changing os.environ['TZ'] without tzset() may not affect localtime() — do not rely on it. The sign in a POSIX string is inverted: 'MSK-3' means UTC+3, and time.timezone stores the offset west of UTC, i.e. -10800. The zone changes for the whole process; for zones in data, datetime with zoneinfo is more reliable than reconfiguring the process. Windows lacks the function.

Examples

import os, time
os.environ['TZ'] = 'MSK-3'
time.tzset()  # → ? на Windows AttributeError
print(time.tzname, time.timezone)  # → ('MSK', 'MSK') -10800
print(time.localtime(0).tm_hour)  # → 3

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy