I have aware datetime instances (where tzinfo = "America/Los_Angeles"
) that I would like to save to a model.
Should I convert it to UTC somehow before saving? Or can I just save it as is, since it's aware of its own timezone? Do I need to convert it to users' timezones later with activate()
, or will Django do that for me, since the instance is aware?
I'm most curious what the conventions are in regards to this. Thanks in advance.
If it is timezone aware and you have USE_TZ
set to True
in your settings.py
django will automatically convert it to UTC when you save it.
When you retrieve it from the DB later it will be timezone aware but set to UTC: django will not save the timezone it used to be.
When you display the datetime in a template it will be converted to the timezone set by TIME_ZONE
in your settings.py
, unless you utilize django's timezone utilities to activate a different timezone.