1

I have read that there is a lot of timezone support available in Django 1.4, but how does one obtain user's timezone in Django 1.3?

Once I have the timezone i.e. something like 'Europe\London' or 'GMT+4:00', it is easy to use a middleware to set it into the request.META dict so that it is available with every request...

Optimus
  • 2,716
  • 4
  • 29
  • 49

1 Answers1

0

The user's timezone isn't normally available to the server. If you look at your own web browser's request headers in something like http://www.myhttp.info/ you'll see there's nothing in there that gives a clue to your timezone.

However, if you can run some Javascript on the client side, you can use the Date class constructor and Date.UTC to examine the difference between local time and UTC on the client. That difference is the current time offset, which is the best you can reliably do.

aecolley
  • 1,973
  • 11
  • 10
  • 1
    Are you really sure? then, how does Django 1.4 support it? you can do something like `tz = request.session.get('django_timezone'); if tz: timezone.activate(tz)` in a middleware in Django 1.4 and you get user's timezone everywhere when available, check out this https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/ – Optimus Oct 23 '12 at 20:37
  • It doesn't go that far. At it says that Django can't automatically determine the user's timezone, but it provides tools to help you get that information from the user. – aecolley Oct 23 '12 at 20:45