pytz

Utilities

Timezone conversions

Try pytz in PyRun

What is pytz?

pytz brings the Olson timezone database to Python. It allows accurate and cross-platform timezone calculations, supporting hundreds of timezones from around the world. pytz is the standard choice when you need to convert datetime objects between timezones or work with timezone-aware datetimes in Python.

pytz is bundled in Pyodide's Python distribution and is available instantly in PyRun. You can explore timezone conversions, work with DST-aware datetimes, and format times for different locales without any installation.

Code Example

Convert datetimes across global timezones.

Pytz Timezone Conversions
Try in Editor
from datetime import datetime
import pytz

event_utc = datetime(2025, 12, 31, 23, 0, 0, tzinfo=pytz.utc)
print("New Year UTC:", event_utc.strftime("%Y-%m-%d %H:%M %Z"))

zones = [
    "America/New_York",
    "Europe/London",
    "Asia/Kolkata",
    "Asia/Tokyo",
    "Australia/Sydney",
]

print("\nNew Year around the world:")
for tz_name in zones:
    tz = pytz.timezone(tz_name)
    local_dt = event_utc.astimezone(tz)
    print(f"  {tz_name:<25} {local_dt.strftime('%Y-%m-%d %H:%M %Z')}")

Why run pytz in PyRun?

  • Zero setup — no pip install, no virtual environment, no Python download
  • Instant results — powered by WebAssembly, runs locally in your browser
  • Share your code — generate a link and anyone can run it instantly
  • Works offline — after first load, PyRun runs without internet
Open editor with pytz example

Related Packages