- Create a
datetime
object with the UTC time zone info. - Convert the previous
datetime
object withastimezone
method.
Here is a example that convert 2025-01-01T00:00Z
to your local time.
from datetime import datetime
from zoneinfo import ZoneInfo
utc = datetime(2025, 1, 1, 0, 0, tzinfo=ZoneInfo("UTC"))
localtime = utc.astimezone(tz=ZoneInfo("localtime"))
Note
On Windows and some minimum container environment, installing tzdata
pakage might be required.
Top comments (0)