如何使用Moment.js解析给定的日期字符串?
我希望使用MOMM.JS进行以下日期字符串的格式,但它给出了无效的日期。
var dateString = '2/17/2016 12:16PM GMT-05:00';
var pattern = 'MM/DD/YYYY h:mma ZZ';
var testDate = moment(dateString).format(pattern); //Invalid Date
如何正确解析它,还是有其他方法可以做到?
I want the following date string to be formatted using moment.js but it gives invalid date.
var dateString = '2/17/2016 12:16PM GMT-05:00';
var pattern = 'MM/DD/YYYY h:mma ZZ';
var testDate = moment(dateString).format(pattern); //Invalid Date
How to parse it correctly or is there any other way to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用模式作为第二参数函数函数
只需在文档中 : htttp:htttp:http:// mommsjs .com/docs/#/parsing/string-format/
Just use pattern as second parameter in moment function
more here in the docs: http://momentjs.com/docs/#/parsing/string-format/
您可以尝试:
You can try it: