javascript - moment js date library, formatting on IE gives a NaN - Stack Overflow

im using moment js date library to format a date, but on IEi get a NaN on the output. It works fine on

im using moment js date library to format a date, but on IE i get a NaN on the output. It works fine on other browsers, like Chrome, FF, etc.

var value = "2015-11";

moment(value).format("YYYY-DD-01 00:00")    
> "0NaN-NaN-01 00:00"   

I was able to fix it by adding the same pattern on moment constructor like below:

> moment(value,"YYYY-DD-01 00:00").format("YYYY-DD-01 00:00")   
"2015-11-01 00:00"  

Is it a good practice to add this pattern on the constructor, for all moment objects creation so it can work also on IE?

im using moment js date library to format a date, but on IE i get a NaN on the output. It works fine on other browsers, like Chrome, FF, etc.

var value = "2015-11";

moment(value).format("YYYY-DD-01 00:00")    
> "0NaN-NaN-01 00:00"   

I was able to fix it by adding the same pattern on moment constructor like below:

> moment(value,"YYYY-DD-01 00:00").format("YYYY-DD-01 00:00")   
"2015-11-01 00:00"  

Is it a good practice to add this pattern on the constructor, for all moment objects creation so it can work also on IE?

Share Improve this question asked Jul 25, 2013 at 7:35 dotmindlabsdotmindlabs 9083 gold badges13 silver badges35 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

The input format should match what you are providing:

var value = "2015-11";
moment(value, "YYYY-MM")

If you want to format it differently for output, that's when you use the .format method.

var value = "2015-11";
var m = moment(value, "YYYY-MM")
var s = m.format("YYYY-MM-DD HH:MM")

Note that you were specifying DD which is the day formatter. But based on the usage, I think you meant MM for month.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743995851a4540622.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信