Categories
JavaScript Answers

How to convert UNIX timestamp to calendar date moment.js and JavaScript?

Spread the love

Sometimes, we want to convert UNIX timestamp to calendar date moment.js and JavaScript.

In this article, we’ll look at how to convert UNIX timestamp to calendar date moment.js and JavaScript.

How to convert UNIX timestamp to calendar date moment.js and JavaScript?

To convert UNIX timestamp to calendar date moment.js and JavaScript, we call moment.unix with the timestamp in seconds and format.

For instance, we write

const dateString = moment.unix(value).format("MM/DD/YYYY");

to call moment.unix with the value UNIX timestamp number to parse it into a moment object.

Then we call format with "MM/DD/YYYY" to return a date string in MM/DD/YYYY format according to the timestamp value.

Conclusion

To convert UNIX timestamp to calendar date moment.js and JavaScript, we call moment.unix with the timestamp in seconds and format.

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 *