How to convert date to UTC format in JavaScript?

new Date() will give you the current date and time in JavaScript. To convert the local date and time to UTC string format you can make use of the toUTCString() method.

let currentDate = new Date();
let utc = currentDate.toUTCString();
console.log(utc);
// "Mon, 26 Jul 2021 18:23:10 GMT"