-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always use UTC when getting the current time #11
Comments
in settings.py you have to change the timezone. |
@serajushsalekin No, From the docs:
In [1]: settings.TIME_ZONE
Out[1]: u'America/Chicago'
In [2]: timezone.now()
Out[2]: datetime.datetime(2018, 5, 1, 15, 29, 46, 420714, tzinfo=<UTC>) |
its return UTC because it is default. USE_I18N = True USE_L10N = True USE_TZ = True |
@serajushsalekin Yes, |
https://stackoverflow.com/questions/16037020/djangos-timezone-now-does-not-show-the-right-time >>> from django.utils import timezone
>>> timezone.now()
datetime.datetime(2019, 9, 19, 12, 30, 44, 798658, tzinfo=<UTC>)
>>> timezone.localtime(timezone.now())
datetime.datetime(2019, 9, 19, 14, 31, 2, 11144, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)
>>> |
There are a number of places in the code that use
According to the docs, this returns the date in the local timezone.
This could lead to a bug where a user could get different results based on the location of the app server.
I believe the fix is to do this instead:
Which will always return the date for UTC.
The text was updated successfully, but these errors were encountered: