[英]moment invalid date in firefox, safari
I am using moment Javascript plugin to format the date,it works in chrome but not in firefox nor Safari. 我正在使用一下Javascript插件来格式化日期,它可以在chrome中使用,但不能在Firefox和Safari中使用。
here is the code I am using: 这是我正在使用的代码:
var date = new Date(deadline.value);
alert(date); //prints out "Sat Feb 21 2015 00:00:00 GMT+0000 (GMT)"
deadline.value = moment(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()).format();
alert(deadline.value); //prints "Invalid date"
The moment docs (see parsing ) note browser support for parsing strings is inconsistent. 当文档(请参阅parsing )注意到浏览器对字符串的支持不一致时。 This chart shows that only the UTC version of "YYYY-MM-DD" is supported in Firefox (v4+) currently.
该图表显示了Firefox(v4 +)当前仅支持UTC版本的“ YYYY-MM-DD”。
UTC: 2009-07-12
UTC:
2009-07-12
Local: 2009-7-12
当地:
2009-7-12
So, you need to pad the month with a zero for the format to be valid. 因此,您需要使用零填充月份以使格式有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.