简体   繁体   中英

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.

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. This chart shows that only the UTC version of "YYYY-MM-DD" is supported in Firefox (v4+) currently.

UTC: 2009-07-12

Local: 2009-7-12

So, you need to pad the month with a zero for the format to be valid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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