pytz library
- Install
pytz
library from the command line:
pip install pytz
- Convert date and time from one time zone to another:
import datetime
import pytz
dateTimeFormat = '%Y-%m-%d %H:%M:%S'
fromTz = pytz.timezone('Europe/London')
toTz = pytz.timezone('America/New_York')
fromDateTime = '2020-09-12 20:30:00'
dt = datetime.datetime.strptime(fromDateTime, dateTimeFormat)
dt = fromTz.localize(dt)
dt = dt.astimezone(toTz)
toDateTime = dt.strftime(dateTimeFormat)
print(toDateTime)
Leave a Comment
Cancel reply