Category: zoneinfo

Problem

Convert timestamps between timezones.

Solution

  utc = dt.replace(tzinfo=ZoneInfo("UTC"))
local = utc.astimezone(ZoneInfo("America/New_York"))
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path