0

I have a JSON file with date format in the form of 2021-09-21 15:37:29.590 +03:00.

How can we convert it to a Date in a T-Z Format ?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
JAN
  • 21,236
  • 66
  • 181
  • 318

1 Answers1

2

You can pass it into the Date constructor and call toISOString.

const convert = (dateString) => new Date(dateString).toISOString();

console.log(convert('2021-09-21 15:37:29.590 +03:00')); // 2021-09-21T12:37:29.590Z
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • In Safari throws "RangeError: Invalid Date". See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Oct 05 '21 at 20:12