Member-only story
Convert a UNIX Timestamp to a Calendar Date with Moment.js?
A tutorial on how to convert a UNIX timestamp to a calendar date with Moment.js.
Sometimes, we want to convert a UNIX timestamp to a calendar date with Moment.js.
In this article, we’ll look at how to convert a UNIX timestamp to a calendar dare with Moment.js.
💡 Speed up your blog creation with DifferAI.
Available for free exclusively on the free and open blogging platform, Differ.
Use the unix() and format() Methods
We can use the unix()
method to create a moment object from a timestamp.
Then we can use the format()
method to format the date into a calendar date.
For instance, we can write:
import moment from 'moment'
const dt = +new Date(2021,1,1)
const dateString = moment.unix(dt / 1000).format("MM/DD/YYYY");
console.log(dateString)