How to format the date and time into UTC format?

Viewed 830

I'm working in nodejs. I have the input has date and time "1/6/2022, 2:49:22 AM". need to convert the date and time to UTC format "2022-01-05T13:04:22.137Z". please help me with the solution.

code:

let date =new Date().toLocaleString("en-US", { timeZone: "Pacific/Chatham" }); console.log(date);

how to convert this date and time "1/6/2022, 2:49:22 AM" into UTC format "2022-01-05T13:04:22.137Z".

kindly help me with the solution.

1 Answers

In javascript

var isoDateString = new Date().toISOString();
console.log(isoDateString);

The toUTCString() method returns a date object as a string, according to UTC.

Tip: The Universal Coordinated Time (UTC) is the time set by the World Time Standard.

Note: UTC time is the same as GMT time.

Source

Related