Home > Back-end >  Convert Date without "T" and "Z" to Date with T-Z Format
Convert Date without "T" and "Z" to Date with T-Z Format

Time:10-05

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 ?

CodePudding user response:

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

  • Related