Categories
JavaScript Answers

How to convert a date to GMT with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *