Skip to content

Instantly share code, notes, and snippets.

@mebusw
Created May 29, 2014 00:37
Show Gist options
  • Save mebusw/48ef02090b2156407a1c to your computer and use it in GitHub Desktop.
Save mebusw/48ef02090b2156407a1c to your computer and use it in GitHub Desktop.
timezone and datetime in Django
from django.utils import timezone
# Suppose in settings.py, TIME_ZONE = 'Asia/Shanghai'
timezone.now()
# >>> datetime.datetime(2014, 5, 29, 0, 35, 19, 523838, tzinfo=<UTC>)
timezone.localtime(timezone.now())
# >>> datetime.datetime(2014, 5, 29, 8, 35, 29, 427944, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment