简体   繁体   English

Moment.js无法解析日期字符串

[英]Moment.js cannot parse string to date

i have a string in javascript. 我在javascript中有一个字符串。 The string is in this format: 14. November 2018 该字符串的格式为: 14. November 2018

Now I want to create a Javascript date object. 现在,我想创建一个Javascript日期对象。 I tried this with moment.js 我尝试了一下moment.js

moment('14. November 2018').format('DD. MMM YYYY');

The browser shows this error: 浏览器显示此错误:

Invalid date

What is wrong with my code? 我的代码有什么问题?

I solved the problem by reading the docs again. 我通过再次阅读文档解决了问题。 The right way is: 正确的方法是:

moment('14. November 2018', 'DD. MMMM YYYY');

尝试这个

moment(str, 'DD. MMMM YYYY').toDate();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM