Last active
December 14, 2015 14:58
-
-
Save ferrouswheel/5104085 to your computer and use it in GitHub Desktop.
If you are using Django with USE_TZ=True, then Django stores times in UTC and various template utilities help to convert to the user's/current timezone as necessary. However, when serialising objects to JSON (which many API libraries do) they'll often directly convert the UTC time. This might be what you want, but you might also be using the API…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assuming utc_datetime is the datetime to convert: | |
from django.utils import timezone | |
current_tz = timezone.get_current_timezone() | |
local_time = current_tz.normalize(utc_datetime).astimezone(current_tz) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment