I'm interested in retrieving the current zoneinfo string ("America/Los Angeles", "Europe/London", etc.) that the user currently has set for their OS in JavaScript. I've found how to get the current offset in seconds, offsets at specific dates, and less exact time zones (PST, etc.) but not the Olson zoneinfo. Is this possible?
A:
You'd have to set up an array or hash of the zoneinfo data in Javascript and determine the name based on the time you pick up.
Diodeus
2009-03-03 22:18:44
A:
Nope. Sorry! You might be able to get it via a Java applet using TimeZone, but from JavaScript all you have is the offset from UTC. (Guessing from the timezone name isn't reliable as the names are locale-dependent. You could detect a few common cases by matching with the UTC offset, perhaps, but it'd be a lot of work.)
Generally if you want to support timezones to a level as fine-grained as Olson you'd give the user an explicit selectable timezone control.
bobince
2009-03-03 22:20:40
+2
A:
See fleegix.js's date.Date plugin. You can probably hack out just the parts you need:
function getRegionForTimezone(tz) {
var exc = regionExceptions[tz];
if (exc) {
return exc;
}
else {
reg = tz.split('/')[0];
return regionMap[reg];
}
}
mahmoud
2009-03-03 22:22:36