Categories
JavaScript Answers

How to convert date to UTC using moment.js and JavaScript?

Spread the love

Sometimes, we want to convert date to UTC using moment.js and JavaScript.

In this article, we’ll look at how to convert date to UTC using moment.js and JavaScript.

How to convert date to UTC using moment.js and JavaScript?

To convert date to UTC using moment.js and JavaScript, we can use the moment’s utc method.

For instance, we write

const utcStart = new moment("2022-06-24T09:00", "YYYY-MM-DDTHH:mm").utc();

to create a moment object with the datetime with moment.

Then we call utc to return a moment object with the same date in UTC.

Conclusion

To convert date to UTC using moment.js and JavaScript, we can use the moment’s utc 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 *