Reputation: 45
I am in Eastern Standard Time (EST). Daylight savings time started 2 weeks ago, where clocks were turned forward 1 hour (so 5PM became 6PM). I have USE_TZ = True
. TIME_ZONE is set to “EST”.
In my app, I have a form that submits a date, like 2AM. That date, still 2AM, gets saved in a model as a DateTime field: event.start = date
. I have a view that renders the date, and the page shows 2AM correctly.
The problem: event.start
evaluates to 3AM (EST) / 8AM (UTC), 1 hour later that what it's supposed to be! The input was 2AM, it even renders 2AM in templates, but for some reason internally event.start
is 8AM (UTC) / 3AM (EST).
But for some reason django.utils.timezone.now()
gives me the correct time 2AM, instead of 3AM. My OS system time also gives the correct time, 2AM. I want to schedule a job for 2AM, but it ends up getting scheduled for 3AM instead because event.start
is set to 3AM for some reason!
I want to keep times in UTC. How do I deal with this?
Upvotes: 0
Views: 1024
Reputation: 810
Eastern Standard Time
doesn't have daylight saving time, it is hard offset from UTC. When there are daylight savings places switch from Eastern Standard Time
to Eastern Daylight Time
(EDT).
More information: https://www.timeanddate.com/time/zones/est
Using Olson identifier is usually better solution. They are the identifiers used in IANA timezone database. They are location based, so when the location changes TimeZone (including daylight savings) everything still works.
Example of a place that changes EST <-> EDT:
America/New_York
Try changing TIME_ZONE
from EST
to Olson identifier for your desired location.
Upvotes: 1