Converting UTC datetime to user's local date and time?

This is more a Python question, than a GAE one, unless GAE has some infrastructure to facilitate this (I've made a quick scan but haven't found any reference) Basically, you want to store date/times in UTC timezone (e.g. Use datetime.datetime. Utcnow) along with user timezones, which you can either try to extract from user IPs (using GeoDjango, if avaiable on GAE, or pygeoip; you need some geolocation db like: maxmind.com/app/geolitecity ), or to explicitly ask users about it - which has the advantage that you can ask for a descriptive timezone name, like "Europe/Warsaw". If you ask for just UTC+2, then you loose any indication of DST shifts Then, you can shift from utc to the desired timezone using e.

G pytz : import pytz local_tz = pytz. Timezone(timezone_name) return timestamp_utc. Replace(tzinfo=pytz.

Utc). Astimezone(local_tz). Replace(tzinfo=None) where timestamp_utc is utc datetime that you want to convert, and timezone_name is the mentioned "Europe/Warsaw (Note that I don't know which of these works in GAE, but at least you will know what to look for).

This is more a Python question, than a GAE one, unless GAE has some infrastructure to facilitate this (I've made a quick scan but haven't found any reference). Basically, you want to store date/times in UTC timezone (e.g. Use datetime.datetime. Utcnow) along with user timezones, which you can either try to extract from user IPs (using GeoDjango, if avaiable on GAE, or pygeoip; you need some geolocation db like: maxmind.com/app/geolitecity), or to explicitly ask users about it - which has the advantage that you can ask for a descriptive timezone name, like "Europe/Warsaw".

If you ask for just UTC+2, then you loose any indication of DST shifts. Then, you can shift from utc to the desired timezone using e.g. Pytz: import pytz local_tz = pytz. Timezone(timezone_name) return timestamp_utc.

Replace(tzinfo=pytz. Utc). Astimezone(local_tz).

Replace(tzinfo=None) -- where timestamp_utc is utc datetime that you want to convert, and timezone_name is the mentioned "Europe/Warsaw".(Note that I don't know which of these works in GAE, but at least you will know what to look for).

This is more complicated than I thought. Explicitly asking users is out of the question. GeoDjango looks like a massive library for all sorts of GEO-related stuff, I just want to convert IP addresses into time zones.

Even pytz seems really big. – speedplane Nov 7 '10 at 20:24.

So I did a bit more research into this. To correctly do timezones, you have to follow something like what Tomasz described in his answer. However, if you're willing to tolerate a bit of kludge, you can get 90% of the way there with much less effort.

When the user logs in or does any action on your site, you can use javascript to get their current timezone offset and then send it in your next request: var offset = (new Date()). GetTimezoneOffset() $. Post("post.

Html", "offset="offset.toString(), ... ); Of course this assumes that the user has correctly set their current timezone. This is discussed on a number of other websites: derickrethans.nl/detecting-timezone-by-i... torrentialwebdev.com/blog/archives/152-P....

Ah, very nice, I didn't know this. Still, if you develop e.g. A CRM, then you can't neglect subtleties like DST. – Tomasz Zielinski Nov 7 '10 at 22:42.

Best and easy way for converting Google App Engine datetime in templates: code.google.com/p/dateconv4gae.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions