0

If I run...

moment().format();

I get back 2022-05-25T16:47:05-04:00

But if I use the native browser Date API toISOString() it's not quite the same as Moment...

new Date(Date.now()).toISOString()

This comes back as 2022-05-25T20:47:05.698Z

How can I get the Date API to return the ISO string in the same format that moment defaults to? The documentation for both says it uses ISO 1806, but yet they are slightly different.

Carson
  • 1,147
  • 5
  • 19
  • 41
  • It's the same, it's just in UTC. – pilchard May 25 '22 at 20:54
  • @pilchard ahh right, but how do I get it in the non-UTC way with the Date API like how Moment defaulted to? I'm not very familiar with time formats to know what thats called or how to do it. We want to switch from moment, but have none of the time strings change. – Carson May 25 '22 at 20:56
  • js dates are stored in UTC so there is no offset stored. What offset would you expect, perhaps the system's local time? If so you'll need to parse it yourself, perhaps with `getTimezoneOffset`. – pilchard May 25 '22 at 20:57

0 Answers0