Sometimes, we want to convert a date to GMT with JavaScript.
In this article, we’ll look at how to convert a date to GMT with JavaScript.
How to convert a date to GMT with JavaScript?
To convert a date to GMT with JavaScript, we use the toUTCString method.
For instance, we write
console.log(new Date("Fri Jan 20 2022 11:51:36 GMT-0500").toUTCString());
to call the toUTCString method to return a the date as a string in UTC.
Conclusion
To convert a date to GMT with JavaScript, we use the toUTCString method.