How to get the timezone of the user's web browser?

74 views
Skip to first unread message

peterept

unread,
Apr 9, 2008, 1:48:44 PM4/9/08
to Google App Engine
I'm storing date/time in UTC in the db. When displaying I want to show
them converted to the user's current timezone (of the browser they are
using).

TIA,

Peter

Dustin Sallings

unread,
Apr 9, 2008, 3:24:26 PM4/9/08
to Google App Engine

This doesn't have anything to do with GAE. You're asking your
question in the wrong part of google.

Ryan Mulligan

unread,
Apr 9, 2008, 3:54:03 PM4/9/08
to google-a...@googlegroups.com
I don't entirely agree. Google Accounts has information about user's timezones, because you can set it ony our account settings page. The root question is, do they expose this timezone to us?

rm

Brett

unread,
Apr 9, 2008, 5:17:15 PM4/9/08
to Google App Engine


On Apr 9, 12:54 pm, "Ryan Mulligan" <r...@ryantm.com> wrote:
> I don't entirely agree. Google Accounts has information about user's
> timezones, because you can set it ony our account settings page. The root
> question is, do they expose this timezone to us?

Google Accounts do not always have timezone information. Many products
let you set this to something specific (see Google Calendar).

peterept

unread,
Apr 10, 2008, 11:50:02 AM4/10/08
to Google App Engine
It would be a great feature to add to GAE in the future (have a
generic user settings page).

For now, here is my summary of the options for GAE/DB apps dealing
with UTC & timezones:

1. Leave the date/time in a specific timezone (such as the location of
your server or the site owner) for anonymous users.

Eg: Engadget shows time in East Coast Time (EST) USA; Sydney Morning
Herald (www.smh.com.au) always shows local Sydney time.

2. Same as 1, but provide a settings screen for users to set their
current timezone (either a user account, or a anonymous settings
stored in a cookie)

Eg: Most forums such as phpBB use this method.

3. Automatically detect the timezone of the browser using javascript
date object (this requires browser to have javascript enabled). Either
a login screen is provided that can post the timezone to the server ,
or the page has a date print function that runs dynamically to adapt
the pages during rendering.The timezone could be stored in a cookie
updated whenever the time on the computer changes.

Eg: GMail sends the timezone when a user uses the login screen
(gmail.com, view source).

4. Avoid the problem completely by using relative time descriptions,
such as 1 minute ago, 10 hours ago, 1 year 125 days ago, In 10 hours,
In 2 weeks 1 day.

Eg: Digg does this for news entries; Facebook does this for status
updates.

5. Infer the timezone from the IP address.

Eg: ip2location.com provides the lookup. Can be costly and adds to
the request time while the server has to do the lookup.

BTW: Credit to mrshoe for emailing me about using javascript in point
(3) above, use: "new Date().getTimezoneOffset()" to get the tz.

Peter


On Apr 9, 2:17 pm, Brett <brettalici...@gmail.com> wrote:
> On Apr 9, 12:54 pm, "Ryan Mulligan" <r...@ryantm.com> wrote:
>
> > I don't entirely agree. Google Accounts has information about user's
> > timezones, because you can set it ony our account settings page. The root
> > question is, do they expose thistimezoneto us?
>
> Google Accounts do not always havetimezoneinformation. Many products
> let you set this to something specific (see Google Calendar).
>
>
>
> > On Wed, Apr 9, 2008 at 2:24 PM, Dustin <dsalli...@gmail.com> wrote:
>
> > >  This doesn't have anything to do with GAE.  You're asking your
> > > question in the wrong part of google.
>
> > > On Apr 9, 10:48 am, peterept <peter...@gmail.com> wrote:
> > > > I'm storing date/time in UTC in the db. When displaying I want to show
> > > > them converted to the user's currenttimezone(of thebrowserthey are
> > > > using).
>
> > > > TIA,
>
> > > > Peter- Hide quoted text -
>
> - Show quoted text -

mrshoe

unread,
Apr 10, 2008, 1:03:33 PM4/10/08
to Google App Engine
Whoops, that was supposed to go to the list ;)

Thanks for the summary, Peter. I think a lot of people will want to
use these techniques.
Reply all
Reply to author
Forward
0 new messages