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 badges1 Answer
Reset to default 8The 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.