Forums

Timezones flipping back and forth?

I noticed that my timezones keep changing for eastern time to easterntime + 4 hours. (When I do datetime.now() I get either Eastern time or eastern time + 4 hours) I have been adding time_delta(hours = -4) in order to fix for this. Why's this happening?

What version of python are you using?

If 3.3+, have you looked at something like:

datetime.datetime.now(datetime.timezone.utc)

?

Saw an interesting discussion at https://julien.danjou.info/blog/2015/python-and-timezones , for example.

HTH,

Jim

Hmm, it would be strange if timezones are changing. Our servers are all set up to use UTC (which I think is currently 4 hours off eastern time). So datetime.now() and datetime.utcnow() should return the same value.

Do you have a timezone setting somewhere in your code? For example, if you have a Django site with the timezone set, you might get eastern time for code running in a Django context, and UTC for code running outside that context.