At GAE, how can I show the date according to the correct TimeZone client?

In my Google App Engine application, I save the automatic updated date / time in my model:

class MyModel(db.Model):
   date = db.DateTimeProperty(auto_now_add=True)

But this date / time is the local time on the server, according to this time zone.

So, when I would like to display it on my web page, how can I format it according to the client’s time zone ?

Also, how can I find out what time zone the google server is located in?

+5
source share
3 answers

Regarding the second part of your question:

Python() UTC, , . timezone() tzname() DST . GAE Python 2.5.x ; . Python .

:

, .

  • ,

    • IP-
    • ,
    • (?) GET POST, .
  • , JavaScript. " UTC Date (utctime), ". JavaScript , - !

, - - JavaScript? 2009! Marcelo .

+5

, . UTC , , JSON:

json = '{"serverUTCDate":new Date("%s")}' % date.ctime()

, , / :

var localDate = serverUTCDate.getTime() - (new Date()).getTimezoneOffset()*60000;
+2

You can find out the server’s time zone by querying the local time and UTC and see what the difference is. To find out the client’s time zone, you need to have a little Javascript in your template that will tell you, for example. in exchange AJAX. To manipulate time zones as soon as you discover a delta, I suggest pytz, pytz.sourceforge.net/.

+1
source

All Articles