pytz
UtilitiesTimezone conversions
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.
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
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.