How to convert Z hour/minute to time zones #3562
-
I am using a file from NHC that has a column HHMM that is in Z time. How can I convert that to central time, eastern time, etc? |
Beta Was this translation helpful? Give feedback.
Answered by
dopplershift
Jul 11, 2024
Replies: 1 comment
-
As of Python 3.9, there's a from datetime import datetime, UTC
from zoneinfo import ZoneInfo
t_str = '1546'
# Parse, then replace the date as well as specify that the timezone is UTC
dt = datetime.strptime(t_str, '%H%M').replace(year=2024, month=7, day=11, tzinfo=UTC)
# Get the UTC time as EDT
dt.astimezone(ZoneInfo('America/New_York')) gives: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dopplershift
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of Python 3.9, there's a
zoneinfo
module for timezones:gives:
datetime.datetime(2024, 7, 11, 11, 46, tzinfo=zoneinfo.ZoneInfo(key='America/New_York'))