I've been having a very rough time with dealing with Timzones and dates selected in DatePickers. And I'm talking about a scenario where we are not interested in a time component (think Date of Birth).
Most of the DatePickers out there suffer the same problem. A Javascript Date object "backs" them. And even if your date comes down the pipe as UTC, the Javascript date is "Regional", based on the Browser in which the site is loaded.
The fact is, a Date of Birth does not care about Timezones. It is constant. So it is pretty offensive when a user selects a Date of Birth and the previous day is what is actually sent to the server. I almost threw the baby and the bathwater out and went with strings in a text input. That is bullet proof.
I digress. One solution that I have seen in several places (which didn't work reliably for us anyway) is code like this
persons[i].BirthDate = persons[i].BirthDate.replace(/\d+/,
function (n) { return parseInt(n) + new Date().getTimezoneOffset() * 60000; }
I'm curious. Why 60000?
I've also seen this:
//Deal with dates in milliseconds for most accuracy
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
newDateWithOffset = new Date(utc + (3600000*offset));
where offset is something like '+10'. What is the 3600000?
I would like to know what these things do before I put them in production. And perhaps the reason they did not work for us is because we did not understand them properly and did not compensate accordingly in other places e.g. the server.
Thanks.