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.