typestar

Dates, times and zones in Python

Aware datetimes only: a naive one is a bug waiting for a deploy.

from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo

started = datetime(2026, 7, 29, 9, 30, tzinfo=timezone.utc)
local = started.astimezone(ZoneInfo("Europe/London"))

print(started.isoformat())
print(local.isoformat(), local.tzname())
print((started + timedelta(hours=36)).strftime("%a %d %b %H:%M"))
print(datetime.fromisoformat("2026-07-29T09:30:00+00:00") == started)

How it works

  1. timezone.utc or a ZoneInfo makes a datetime aware.
  2. astimezone converts; the instant does not change.
  3. isoformat and fromisoformat round-trip cleanly.

Keywords and builtins used here

The run, in numbers

Lines
10
Characters to type
400
Tokens
107
Three-star pace
105 tpm

At the three-star pace of 105 tokens a minute, this run takes about 61 seconds.

Type this snippet

Step 2 of 3 in Configuration & time, step 33 of 41 in Domain tools.

← Previous Next →