Go – What’s the best way to display accurate current time and date in Django

django

Currently my method involves creating a context processor
which is then included sitewide. However, I notice I have
problems accounting for daylight saving time changes. I live
outside of the U.S. BTW and my server is in the U.S. but its
time zone is set to mine. However since we don't account for
daylight saving time, it's always one hour ahead of my local
time.

Any idea how to account for this? I have used timedelta -1
in the past but somehow I don't feel this is the right
solution.

Best Solution

The time-zone you have set on the server shouldn't matter from within your Django app. Django will return the time based on what your TIME_ZONE variable is set to in your settings.py, not what you have set on the server. For example, one server may serve multiple Django-powered sites, each with a separate time-zone setting.

See: http://docs.djangoproject.com/en/dev/ref/settings/#time-zone.

Just make sure you set your TIME_ZONE variable to the Zoneinfo name (ie. America/Belize) instead of just GMT-6, because that won't account for daylight savings. Using the Zoneinfo name, Django will return the daylight-savings aware version of the time. So set that up right, and you should be able to get the time-zone you want in your Django app.

{% now h:ia %}

That'll return the time in a format like 9:30am.