I store dates on server side in UTC timezone.
When client (browser) wants to pass some date to server it sends date like
"Tue Jan 03 2012 16:50:32 GMT+0400 (Russian Standard Time)"
- Is this format standard across all browsers?
- If 1. is false, how can I redefine the
Dateformat function? Is this a good practice? - How can I convert JS
Dates to a UTCjava.util.Datewithjava.text.SimpleDateFormat?
UPDATE
I thought that passing date as formatted string (with timezone part) will cause less headache since I shouldn’t bother to convert dates to UTC on client side. So I avoid any date conversions in JS code.
You should send the number of milliseconds since epoch (1 Jan 1970 UTC) that is available via the
+prefix operator as in+new Date(2012, 0, 1).Sending anything with a timezone requires both machines to have the same timezone definitions which means you will likely end up with subtle bugs where two dates occurred in one order on one machine but in a different order on another. You can eliminate that whole class of bugs by using the millis since epoch representation.
To answer your questions:
Date.prototype.toStringandtoUTCStringare both implementation dependent buttoISOStringis reliable.Whereas http://es5.github.com/#x15.9.5.2 says
http://es5.github.com/#x15.9.1.15