How to get date and time from another timezone in Python?
How to Get Date and Time from Another Timezone in Python
Handling timezones correctly is one of the hardest parts of programming. In 2026, the “naive” datetime objects are considered a bad practice.
The Modern Way: zoneinfo (Python 3.9+)
You no longer need the third-party pytz library for most tasks. Python now includes zoneinfo in the standard library.
from datetime import datetime
from zoneinfo import ZoneInfo
utc_time = datetime.now(ZoneInfo("UTC"))
ny_time = utc_time.astimezone(ZoneInfo("America/New_York"))
print(ny_time)
Why This Matters
- DST Handling: The
zoneinfodatabase automatically handles Daylight Saving Time transitions, which change every year. - Database Storage: The 2026 standard is to always store timestamps in UTC in your database and only convert to the user’s local timezone when displaying the data in the UI.