Python Glossary Русский

Python 3.2+datetimeterm

datetime.timezone

time zone

A time zone with a fixed offset from UTC (a subclass of tzinfo).

Syntax

datetime.timezone(offset)

This is a fixed offset and nothing more — no daylight saving transitions — so real zones like Europe/Moscow need ZoneInfo from the zoneinfo module (Python 3.9+). The offset must be strictly less than one day in magnitude, otherwise you get a ValueError. Keep replace(tzinfo=...), which only attaches a label and leaves the clock reading untouched, distinct from astimezone(), which actually converts the instant to another zone.

Examples

import datetime
tz = datetime.timezone(datetime.timedelta(hours=3))
print(tz)   # → UTC+03:00
print(datetime.timezone.utc)   # → UTC

See also

Open in the full glossarydocs.python.orgReport an inaccuracy