Categories
JavaScript Answers

How to convert a JavaScript timestamp into UTC format?

Spread the love

Sometimes, we want to convert a JavaScript timestamp into UTC format.

In this article, we’ll look at how to convert a JavaScript timestamp into UTC format.

How to convert a JavaScript timestamp into UTC format?

To convert a JavaScript timestamp into UTC format, we can call the toUTCString method.

For instance, we write:

const s = (new Date(1291656749000)).toUTCString()
console.log(s)

We create a date with a timestamp.

Then we call toUTCString to return the UTC date string from the date.

As a result, s is 'Mon, 06 Dec 2010 17:32:29 GMT'.

Conclusion

To convert a JavaScript timestamp into UTC format, we can call 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 *