Sometimes, we want to return a date in UTC with Moment.js.
In this article, we’ll look at how to return a date in UTC with Moment.js.
How to return a date in UTC with Moment.js?
To return a date in UTC with Moment.js, we can use the moment.utc method.
For instance, we write:
const d = moment.utc('2022-10-29T00:00:00.000')
console.log(d)
to call moment.utc with the date string we want to parse.
As a result, d is a moment object with the date time in UTC.
Conclusion
To return a date in UTC with Moment.js, we can use the moment.utc method.