views:

295

answers:

2

I need to determine the client timezone (e.g. CET, GMT, EST) in JS. Getting the offset is straightforward, but doesn't have all the info necessary to determine the TZ, at least not easily. I have a feeling it might be possible to use a combination of offset, whether DST is in use and in effect, etc. but I'm hoping someone else has done the work already, especially considering the weird exceptions when dealing with time.

This question is similar but both the question and the answer are based on the (incorrect) assumption every browser's DateString format includes the name of the timezone - which it does not. That is an implementation detail.

So, with that I am currently stuck.

+1  A: 

What I would do is determining the standard and daylight offset (which sounds like you already knew. If not, you can start with this reference http://onlineaspect.com/examples/timezone/detect_timezone.js by Josh Fraser). Determining the time zone can always be done on the server side once the standard and daylight offsets are known. A Ajax call can then be used so that no page refresh is ever needed. End result is you now have the time zone on the JavaScript side.

Khnle
+1  A: 

See this question. It's not doable in the general case, but for picking a default timezone from a shortlist of likely cases, you can make a decent guess.

Allow the user to override it for when you guess wrong.

bobince
Indeed, this is just needed to supply a decent guess. If it can prefill correctly for 90% of users I'd be very happy.
Rex M