The localize
method takes a datetime
, not a string. So the call to strftime
should be removed.
import datetime
import pytz
from pytz import timezone
dt = "8/8/2013 4:05:03 PM"
unaware_est = datetime.datetime.strptime(dt,"%m/%d/%Y %I:%M:%S %p")
localtz = timezone('US/Eastern')
aware_est = localtz.localize(unaware_est)
This still doesn't give you UTC. If you want that, you need to follow it up with:
utc = aware_est.astimezone(pytz.utc)