What's the difference between datetime in ISO 8601 and UTC formats in javascript?

myroman picture myroman · Jan 23, 2014 · Viewed 45.3k times · Source

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.

Answer

Pinal picture Pinal · Jan 23, 2014

They're for different purposes.

  • UTC is the primary time standard by which the world regulates clocks and time.
  • ISO is standard format time. ISO also supports 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.