0

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())
user28221
  • 47
  • 3
  • https://stackoverflow.com/questions/4770297/convert-utc-datetime-string-to-local-datetime -- Possible answer – Rajat Mishra Apr 03 '20 at 04:19
  • 1
    `strptime` gives you a naïve datetime object. Make that *aware* as EST time, then convert its timezone. – deceze Apr 05 '20 at 05:50

0 Answers0