0

According to MDN, new Date() supports ISO 8601 encoded datetime strings. They mention that different browsers have inconsistent behaviour regarding the time zone, which I have observed. Other questions on this topic recommend using a parsing library.

However, ISO 8601 supports specifying that the time is UTC with a Z at the end of the string. I have tested the code

new Date("2017-05-31T10:20:46.085755Z")

in Chrome 58, Firefox 43, Safari 9, and IE 11, and all of them correctly parse the date as UTC.

My date string is always in this exact format. So are there any browsers where this doesn't work? If the built-in function works for my use case, I would much rather not use a library.

Dan
  • 12,409
  • 3
  • 50
  • 87
  • The other questions recommend a library due to the ease of use when converting date strings to different formats. If you know how to do it yourself without a library, go ahead! – evolutionxbox Jun 06 '17 at 12:01
  • @evolutionxbox My problem is that I don't have every popular browser/OS combination on hand to test it. – Dan Jun 06 '17 at 12:02
  • 1
    It depends on your intepretation of `popular browser/OS`. This may help you decide: http://dygraphs.com/date-formats.html – Jamiec Jun 06 '17 at 12:06
  • I guess some browsers might have problems with that millisecond format. But no, as long as you always have that `Z` in the end, there's no problem with the timezone. – Bergi Jun 06 '17 at 12:07

0 Answers0