datetime.timezone
The built-in tzinfo for fixed offsets. It knows nothing about daylight saving: +01:00 is +01:00 all year. For real regional zones (Europe/Paris) use the separate zoneinfo module.
Demo
from datetime import timedelta, timezone tz = timezone(timedelta(hours=5, minutes=30)) (tz, str(tz))
A zero offset with no name gives back the timezone.utc singleton, so its repr is datetime.timezone.utc. Converting keeps the instant: 23:00 UTC shown at -07:00 is 16:00 the same day, at +09:00 it would already be the next day. The name is a free-form label — timezone(timedelta(hours=3), "PST") is accepted and compares equal to any other +03:00.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| offset | timedelta | yes | The UTC offset, strictly between -timedelta(hours=24) and timedelta(hours=24). Seconds and microseconds are allowed (3.7+). |
| name | str | no (None) | What tzname() and %Z return. Without it the name is generated: 'UTC+05:30', or 'UTC' for a zero offset. |
Return value
timezone — A tzinfo whose utcoffset() is always `offset` and whose dst() is always None.
Common patterns
from datetime import datetime, timedelta, timezone ist = timezone(timedelta(hours=5, minutes=30), 'IST') local = datetime.fromisoformat('2026-09-29T12:00Z').astimezone(ist)
from datetime import datetime from zoneinfo import ZoneInfo paris = datetime(2026, 7, 1, 12, tzinfo=ZoneInfo('Europe/Paris'))
from datetime import timedelta, timezone tz = timezone(timedelta(minutes=-js_offset_minutes))
Examples
Pitfalls
from datetime import timezone timezone(-5)
from datetime import timedelta, timezone timezone(timedelta(hours=-5))
from datetime import datetime, timedelta, timezone datetime(2026, 7, 1, 12, tzinfo=timezone(timedelta(hours=1))).isoformat()
from datetime import datetime, timedelta, timezone datetime(2026, 7, 1, 12, tzinfo=timezone(timedelta(hours=2))).isoformat()
from datetime import timedelta, timezone timezone(timedelta(hours=24))
from datetime import timedelta, timezone timezone(timedelta(hours=14))
When to use
- UTC (timezone.utc or its alias UTC) — the right tzinfo for stored timestamps
- Offsets that really are fixed: parsed from ISO text, from an API, or a fixed business rule
- Regions with daylight saving time → zoneinfo.ZoneInfo("Europe/Paris")
- Custom rules → subclass tzinfo (timezone itself cannot be subclassed)
Notes
FAQ
timezone(timedelta(hours=5, minutes=30)) for +05:30, timezone(timedelta(hours=-5)) for -05:00, and timezone.utc (or UTC on 3.11+) for zero. Pass it as tzinfo= when building a datetime, or to astimezone() to convert.