mb52089
mb52089

Reputation: 872

django 1.4 timezones not stored in UTC in db - why?

My settings file has USE_TZ = True and TIME_ZONE = 'GMT'. I have middleware that checks the user's timezone and sets that as the current timezone, which is working correctly. However, when I get a datetime field from a form, and store it in the DB, the stored time is US/Eastern instead of UTC. For example, if I have a user whose timezone is US/Central, and they fill out a form with a datetime field in it and select 8:00 AM, it is stored as 9:00 AM in the database. It should be stored as 13:00 (1 PM) in the database, since the offset from US/Central to UTC is 5 hours right now, given daylight savings time. Instead, it's only offset 1 hour, which suggests US/Eastern.

Any help is greatly appreciated.

Upvotes: 0

Views: 457

Answers (1)

mb52089
mb52089

Reputation: 872

I just figured out that it is actually working correctly, but that the times shown in the django admin are relative to my local time, thus the confusion. The time as stored in the database is actually correctly offset UTC. Rookie mistake, but I'm a rookie.

Upvotes: 1

Related Questions