views:

119

answers:

5

For my project(a web and iPhone based application) i need to collect a user's timezone so as to show him/her the relevant data.Some of the possibilities that I can think of are :

1.Getting it using user's IP (But what if the user is behind a proxy server)
2.Sending it with request params(But that will require extra param to be attached with request. Or may be collecting once for a session)
3.Passing it through cookies(Has same implication as setting in the parameters)
4.Based on user's zip code which I am collecting at the time of registeration but for unregistered user's that can browse through the app will not be able to see the relevant data.

So all in all each approach that I can think of now has one or more drawbacks. I just want to know what other approaches are there and which one is the best to use in such a case where user experience is not affected and user is not explicitly asked about his/her timezone.Also the approach should apply to both web and iPhone.

A: 

I would collect the user's current time using JavaScript, and send it along the first request to last for the whole session.

You'll have to allow for deviations (Maybe +- 15 minutes) but it should be possible to determine the time zone pretty reliably this way.

The next best thing is probably indeed running the user's IP through a geolocation service to find out the country. However, you'll have to maintain a country-to-timezone map to do this properly, and you will have problems with countries that have multiple time zones like the United States or Russia.

Pekka
@pekka i too have thought about these approaches already mentioned in the question but the point is all these require extra processing at client side except running the ip through geolocation services what i am looking forward to is something attached in headers itself but i am not sure if such information can be extracted from http headers or does it really exists there as i have never seen such info in the http request headers.
Hitesh Manchanda
@Hitesh I don't think there are HTTP headers specifying the user's time zone. Fetching the current time in an Ajax call shouldn't be too difficult to do, though.
Pekka
@pekka thanks i guess i will have stick to the ajax call approach for now.
Hitesh Manchanda
A: 

I don't know much about iPhone development, but there might be something in the API that allows you to access the user's preferences, or even the current time displayed to them.

As for the web in general, it's covered extensively in this question.

Fiona Holder
A: 

For the web, you should be able to get it from the user's browser. For the iPhone, I would imagine there's an API for that. At least, ISTR that my iPhone shows the correct local time when I change time zones (I imagine it gets this information from the local cell tower when it connects to it).

TMN
+1  A: 

With JavaScript, you can use new Date().getTimezoneOffset(), if that's of any help. According to MDC, that'll get you the offset in minutes... In my case (Finland), -180.

AKX
+1  A: 

For the iPhone SDK on getting timezone... This will get you what you need and adjust it for daylight savings.

NSTimeZone *systimeZone = [NSTimeZone systemTimeZone];
NSString *timeZoneString = [systimeZone localizedName:NSTimeZoneNameStyleShortStandard locale:currentLocale];
if([systimeZone isDaylightSavingTimeForDate:[NSDate date]]){
    timeZoneString = [systimeZone localizedName:NSTimeZoneNameStyleShortDaylightSaving locale:currentLocale];
}

There's great info on the TimeZone objects at the apple docs.

Jesse Wolgamott