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.

John Au-Yeung
JavaScript in Plain English
2 min readJul 6, 2022

Photo by Max Rosero on Unsplash

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)

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

No responses yet

Write a response