Format date with Moment.js Format date with Moment.js javascript javascript

Format date with Moment.js


The 2nd argument to moment() is a parsing format rather than an display format.

For that, you want the .format() method:

moment(testDate).format('MM/DD/YYYY');

Also note that case does matter. For Month, Day of Month, and Year, the format should be uppercase.


Include moment.js and using the below code you can format your date

var formatDate= 1399919400000;var responseDate = moment(formatDate).format('DD/MM/YYYY');

My output is "13/05/2014"


moment().format();                                // "2019-08-12T17:52:17-05:00" (ISO 8601, no fractional seconds)moment().format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Monday, August 12th 2019, 5:52:00 pm"moment().format("ddd, hA");                       // "Mon, 5PM"