首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用Moment.js设置日期格式

使用Moment.js设置日期格式
EN

Stack Overflow用户
提问于 2013-04-14 07:08:11
回答 6查看 844.7K关注 0票数 329

我有一个以下格式的字符串:

代码语言:javascript
复制
var testDate = "Fri Apr 12 2013 19:08:55 GMT-0500 (CDT)"

我想使用Moment.js获取它在这种格式的mm/dd/yyyy : 04/12/2013显示。

我试着用这种方法来做,

代码语言:javascript
复制
moment(testDate,'mm/dd/yyyy');

哪些错误并显示为there is no such method called replace?我是不是以错误的方式来处理这个问题?

编辑

我还应该提到,我使用的是为Meteor.js打包的预打包版本的Moment.js

代码语言:javascript
复制
Object [object Date] has no method 'replace' : The Exact error from the console

堆栈跟踪:

代码语言:javascript
复制
 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) 
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15993913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档