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 ( 



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.


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"

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>


May be this helps some one who are looking for multiple date formats one after the other by willingly or unexpectedly. Please find the code: I am using moment.js format function on a current date as (today is 29-06-2020) var startDate = moment(new Date()).format('MM/DD/YY'); Result: 06/28/20

what happening is it retains only the year part :20 as "06/28/20", after If I run the statement : new Date(startDate) The result is "Mon Jun 28 1920 00:00:00 GMT+0530 (India Standard Time)",

Then, when I use another format on "06/28/20": startDate = moment(startDate ).format('MM-DD-YYYY'); Result: 06-28-1920, in google chrome and firefox browsers it gives correct date on second attempt as: 06-28-2020. But in IE it is having issues, from this I understood we can apply one dateformat on the given date, If we want second date format, it should be apply on the fresh date not on the first date format result. And also observe that for first time applying 'MM-DD-YYYY' and next 'MM-DD-YY' is working in IE. For clear understanding please find my question in the link: Date went wrong when using Momentjs date format in IE 11


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.