Let's say user in CA, US picks up a date, time and timezone:
Worldwide beer marathon starts on 8/15/2013 10:00 am, UTC-08:00
Another user, in Central Europe opens the page where this date and time is displayed. He doesn't want to do time calculations (had few beers already). He just wants to see this date and time:
8/15/2013 19:00
Given the browser receives the date and time information, as entered by user in California:
Is there a way, in javascript, without external web services, to do a correct conversion? That is, to detect that 10am UTC-08:00 should actually be 10am UTC-07:00, since it is Daylight Saving.
Maybe I got wrong understanding of this from the beginning, but I don't want to let the entering user to think whether he should choose UTC-08:00 (PST) or UTC-07:00 (PDT). I assume that since the standard timezone in CA is PST, people don't switch to thinking in PDT in summer time. Or do they?!
In central Europe, standard date is UTC+01:00, Daylight Saving date is UTC+02:00. So that difference between CA and Europe should be 9 hours, except for two periods in a year, when one or the other area switches between Standard and Daylight Saving modes.
Update:
After some more thinking and reading the comments, what I would ideally need is this:
var utcOffset = f('2013-08-15T10:00', 'America/Los_Angeles');
// utcOffset == "-07:00"
var utcOffset = f('2013-11-15T10:00', 'America/Los_Angeles');
// utcOffset == "-08:00"
So far, it looks like the moment.js/timezone plugin, suggested by Guido Preite is capable of doing this (more or less).
Any other way, using browser APIs?
See Question&Answers more detail:
os