Skip to content

Instantly share code, notes, and snippets.

@sharkdp
Created February 8, 2024 20:45
Show Gist options
  • Save sharkdp/c7e6be96c666913d670bbaf840b6e85f to your computer and use it in GitHub Desktop.
Save sharkdp/c7e6be96c666913d670bbaf840b6e85f to your computer and use it in GitHub Desktop.
from datetime import datetime
import pytz
import tzlocal
utc_time_string = "2024-07-01T12:00:00"
utc_time = datetime.strptime(utc_time_string, "%Y-%m-%dT%H:%M:%S").replace(
tzinfo=pytz.utc
)
local_time = utc_time.astimezone(tzlocal.get_localzone())
print(local_time.strftime("%Y-%m-%dT%H:%M:%S%z"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment