Categories
JavaScript Answers

How to convert Moment.js date to users local time zone with JavaScript?

Spread the love

Sometimes, we want to convert Moment.js date to users local time zone with JavaScript.

In this article, we’ll look at how to convert Moment.js date to users local time zone with JavaScript.

How to convert Moment.js date to users local time zone with JavaScript?

To convert Moment.js date to users local time zone with JavaScript, we can use the local method.

For instance, we write

const testDateUtc = moment.utc("2022-01-30 10:00:00");
const localDate = moment(testDateUtc).local();

to create a moment UTC datetime object with moment.utc.

Then we call moment with testDateUtc to create a new moment object.

Finally, we call local on it to return testDateUtc converted to the local time zone.

Conclusion

To convert Moment.js date to users local time zone with JavaScript, we can use the local method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.