5
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.
1
If the server is set to your timezone and you want to display time in your timezone, you should just be able to use something like:
{% now M d, Y h-ia %}
To give something like: Jan 23, 2009 9:21a.m.
See http://docs.djangoproject.com/en/dev/ref/templates/builtins/
- [Django]-How to get checkbox values in django application
- [Django]-How do I fix this error in Python Django involving request.user.is_authenticated() and bool object not callable?
- [Django]-How to include "None" in lte/gte comparisons?
- [Django]-Getting Failed to construct 'Worker' with JS worker file located on other domain
- [Django]-Django – button url
1
With Django 1.4, you can now use the django.utils.timezone to set the current timezone for a given user
- [Django]-How to add custom field in manytomany through table in Django
- [Django]-Connecting a django-registration signal
0
It sounds like, while the time is set to your time, the timezone isn’t.
If this is a Linux server, the timezone is controlled by the file /etc/localtime
This is actually a symbolic link to one of the timezone files in /usr/share/zoneinfo
. The default is probably something like /usr/share/zoneinfo/America/New_York
, but you can change it to /usr/share/zoneinfo/America/Belize
* by doing the following:
ln -sf /usr/share/zoneinfo/America/Belize /etc/localtime
The location will be slightly different if you’re using a different *nix OS. For example, Solaris has timezone files in /usr/share/lib/zoneinfo
This is assuming you have root access on the machine, as you have access to change the system clock.
*Your location is listed as Belize in your profile, in case you wondered where I got that.
0
If you are only concerned with displaying the date and time on the client side, you could just use Javascript, which will use the date and time of the client computer.
There may be reasons you don’t want to do this, but I thought I’d throw it out there anyway.
- [Django]-Wagtail admin icons disappear when running collectstatic and putting everything on S3
- [Django]-AttributeError: 'CombinedExpression' object has no attribute 'default_alias'