Categories
JavaScript Answers

How to use moment.js to convert date to string in mm/dd/yyyy format with JavaScript?

Spread the love

To use moment.js to convert date to string in mm/dd/yyyy format with JavaScript, we use the format method.

For instance, we write

const startDate = moment().format("MM/DD/YYYY HH:mm:ss");

to create a moment object with moment with the current datetime.

Then we call format with a format string to return a string in mm/dd/yyyy format with the time in hours:minutes:seconds 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.