Here is my code that I use to make the datetime timezone aware. I tried to use the recommended approach from the Django docs.
tradeDay = day.trade_date + timedelta(hours=6)
td1 = pytz.timezone("Europe/London").localize(tradeDay, is_dst=None)
tradeDay = td1.astimezone(pytz.utc)
I get the tz_info error. How can I datetime a tz_info attribute?
USE_TZ = True in settings.py
It looks as though
day.trade_date
is actually adatetime.date
object rather than adatetime.datetime
so trying to localize it will cause an error.Try converting
day.trade_date
to adatetime.datetime
first usingcombine()
. You can then add 6 hours and localize it.