format date with moment.js


format date with moment.js

I have a string in this format:
var testDate = “Fri Apr 12 2013 19:08:55 GMT-0500 (CDT)”
I would like to using moment.js get it in this format mm/dd/yyyy : 04/12/2013 for display.
I tried to do it using this method,

Which errors and says there is no such method called replace ? am i approaching this in the wrong way?
I should also mention that i am using a pre packaged version of moment.js, packaged for meteor.js
Object [object Date] has no method ‘replace’ : The Exact error from the console

Stack Trace:
at makeDateFromStringAndFormat (
at moment (
at populateProfileForEdit (
at Object.Template.profile_personal.rendered (
at Spark.createLandmark.rendered (
at Array.forEach (native)
at Function._.each._.forEach (
at _.extend.flush (


Solution 1:

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

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


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

Solution 2:

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”

Solution 3:

For fromating output date use format. Second moment argument is for parsing – however if you omit it then you testDate will cause deprecation warning

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format…

var testDate= "Fri Apr 12 2013 19:08:55 GMT-0500 (CDT)"

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

msg.innerText= s;
<script src=""></script>

<div id="msg"></div>

to omit this warning you should provide parsing format

var testDate= "Fri Apr 12 2013 19:08:55 GMT-0500 (CDT)"

let s= moment(testDate, 'ddd MMM D YYYY HH:mm:ss ZZ').format('MM/DD/YYYY');

<script src=""></script>