What is the best way to collect a user time zone without explicitly asking the user?

For my project (web and iPhone-based applications) I need to collect the user's time zone to show him / her the relevant data. Some of the features I can think of are:

1. Having received it using the user's IP address (but what if the user is behind a proxy server)
2. By sending it with the request parameters (But this will require an additional parameter that will be attached with the request or can be collected once for the session)
3.Passing it through cookies (has the same meaning as setting in the parameters)
4. Based on the user zip code that I collect during registration, but for an unregistered user who can view the application, she will not be able to see the corresponding data.

Thus, in all the approaches that I can now think of, there are one or more disadvantages. I just want to know which other approaches exist, and which one is best used in a case where the user interface is not affected, and the user is clearly not asked a question about his / her time zone. Also, the approach should be applied both to the Internet and to the iPhone.

+4
source share
5 answers

I collected the current time of the user using JavaScript and sent it at the first request for the last session.

You will need to allow deviations (maybe + - 15 minutes), but it should be possible to determine the time zone quite reliably in this way.

The next best thing is probably really launching the user's IP address through the geolocation service to find out the country. However, you will need to save the map β€œfrom country to time” in order to do it right, and you will have problems with countries that have several time zones, such as the United States or Russia.

0
source

For the iPhone SDK to get the time zone ... This will give you what you need and configure it to save daylight.

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

There is great info on TimeZone objects in apple docs .

+2
source

Using JavaScript, you can use new Date().getTimezoneOffset() if that helps any help. According to MDC , this will lead to a shift in minutes ... In my case (Finland) -180.

+1
source

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

As for the Internet as a whole, it is widely covered in this matter .

0
source

For the Internet, you can get it from a custom browser. For the iPhone, I would suggest that there is an API for this. At least ISTR, that my iPhone shows the correct local time when I change time zones (I think it receives this information from the local cellular tower when it connects to it).

0
source

All Articles