formatee la fecha con el momento.js


Tengo una cadena en este formato:

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

Me gustaría usar el momento.js lo obtiene en este formato mm/dd/yyyy : 04/12/2013 para su visualización.

Traté de hacerlo usando este método,

moment(testDate,'mm/dd/yyyy');

¿Qué errores y dice there is no such method called replace? ¿me estoy acercando a esto de la manera equivocada?

Editar:

También debo mencionar que estoy usando una versión pre-empaquetada de moment.js, empaquetado para meteor.js

Object [object Date] has no method 'replace' : The Exact error from the console

Seguimiento de pila:

 at makeDateFromStringAndFormat (http://127.0.0.1:3000/packages/moment/lib/moment/moment.js?b4e3ac4a3d0794023a4410e7941c3e179398b5b0:539:29)
    at moment (http://127.0.0.1:3000/packages/moment/lib/moment/moment.js?b4e3ac4a3d0794023a4410e7941c3e179398b5b0:652:24)
    at populateProfileForEdit (http://127.0.0.1:3000/client/views/home/administration/directory/profiles/profiles.js?acfff908a6a099f37312f62892a22b40f82e5e0f:147:25)
    at Object.Template.profile_personal.rendered (http://127.0.0.1:3000/client/views/home/administration/directory/profiles/profiles.js?acfff908a6a099f37312f62892a22b40f82e5e0f:130:13)
    at Spark.createLandmark.rendered (http://127.0.0.1:3000/packages/templating/deftemplate.js?b622653d121262e50a80be772bf5b1e55ab33881:126:42)
    at http://127.0.0.1:3000/packages/spark/spark.js?45c746f38023ceb80745f4b4280457e15f058bbc:384:32
    at Array.forEach (native)
    at Function._.each._.forEach (http://127.0.0.1:3000/packages/underscore/underscore.js?867d3653d53e9c7a171483edbcad9670e12288c7:79:11)
    at http://127.0.0.1:3000/packages/spark/spark.js?45c746f38023ceb80745f4b4280457e15f058bbc:382:7
    at _.extend.flush (http://127.0.0.1:3000/packages/deps/deps.js?9642a93ae1f8ffa8eb1c2475b198c764f183d693:231:11) 
Author: Warz, 2013-04-14

2 answers

El segundo argumento de moment() es un parsing format rather than an display format.

Para eso, usted quiere el .format() método :

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

También tenga en cuenta que el caso sí importa. Para Mes, Día del Mes y Año, el formato debe estar en mayúsculas.

 407
Author: Jonathan Lonowski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-13 23:29:51

Incluya el momento.js y utilizando el siguiente código puede formatear su fecha

var formatDate= 1399919400000;

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

Mi salida es "13/05/2014"

 32
Author: Akalya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-12 05:50:18