I pick some date and time in javascript and then want to store it on server (.NET). Dates are supposed to be in future from the current moment (so they won't be before 1970). Having read topics here on SO I learnt it's better to store date as a string and people suggest using Date.prototype.toISOString()
or Date.prototype.toUTCString()
. I've read that toISOString()
is not available in IE 7. And I'd like to know other differences, when I should choose one or another function.
The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss. sssZ , respectively). The timezone is always zero UTC offset, as denoted by the suffix Z .
Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z"). Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC.
Use the getTime() method to convert an ISO date to a timestamp, e.g. new Date(isoStr). getTime() . The getTime method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation.
The timezone is always zero UTC offset, as denoted by the suffix " Z ". For Timezone work, moment. js and moment.
They're for different purposes.
ms
in its format.So if you want to send data to the server, send the ISO
, because ISO
is the standard format:
var date = new Date(); sendDate(date.toISOString());
You can also use toISOString
in IE7 polyfill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With