So lets say a user is running my web app from his browser on a different time zone than the application server. I serialize a date on the client-side by using JavaScript's date.getTime()
method. I send the resulting milliseconds through Json and then create a Java Date object on the server-side by calling new Date(millisecondsFromJS)
. I store that on MySql, retrieve it, serialize it again by calling Java's date.getTime()
and send it once again to the client through Json.
If I create a JavaScript Date object with those milliseconds, will it result in the original date? I've successfully gone through this process, but the client and server are currently on the same time zone. I'm not sure if the date will get corrupted in the process if the time zones are different.
As I understand it, using getTime() returns an instant in time that is independent of time zones. If the user captured July 17, 2012 at 4:39 PM CDT, the server might store it as July 17, 2012 at 11:39 PM CEST, for example, but once the server converts this to milliseconds since GMT and the client creates a date from these milliseconds, it would have successfully reconstructed the original July 17, 2012 at 4:39 PM CDT. Is this true?
var now = new Date();
and thennow.toISOString();
– Wolfram Jul 17 '12 at 21:58