Reputation: 7366
I develop web-site with different events. And I want to show event start time in user local time. And I don't know how do that. I try to use this django app django-easy-timezones. But it show time in UTC. My settings.py
TIME_ZONE = 'UTC'
USE_TZ = True
My template:
{% load tz %}
{% localtime on %}
{{ start_time|date:"H:i" }}
{% endlocaltime %}
It's possible to do that without asking a timezone?
Upvotes: 1
Views: 285
Reputation: 11730
There are only three ways to accomplish this without directly asking the user; 1) use a client side application, 2) rely on geo-ip or 3) rely on browser proprietary location services.
Option 1 would require something on the client side that fetchs the system timezone and returns it with a request. In javascript, you can fetch the timezone with a call to getTimezoneOffset()
http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp.
Option 2 would rely on the GeoIP database from maxmind. They have an FAQ on this very topic http://dev.maxmind.com/faq/how-can-i-determine-the-timezone-of-a-website-visitor
The GeoIP2 City database similarly provides the time zone in the location record. To find out how to access this, refer to the documentation for your language’s GeoIP2 API.
Option 3 requires utilization of each browser's proprietary geolocation technology. Here's a link to how todo this with Mozilla https://www.mozilla.org/en-US/firefox/geolocation/
Upvotes: 1