I have a datetime, that originates from a string:
myString = '20200505:1715'
datetime.datetime.strptime(myString, "%Y%m%d:%H%M")
# datetime.datetime(2020, 5, 5, 17, 15)
This datetime happens in 'EST'
.
Following the advice, that one should operate internally only with UTC
datetimes, I would like to convert it accordingly (see: Daylight savings time in Python ).
What is the proper way of doing this?
I know that for now()
this should be done in the following way, as depicted in Daylight savings time in Python, but I wonder how this would look like for an arbitrary parsed datetime?
import pytz
import datetime
utc = pytz.timezone('UTC')
now = utc.localize(datetime.datetime.utcnow())