var a = moment("24 12 1995").format('DD MM YYYY');
alert(a)
// This should be valid but its not.
var a = moment("12 24 1995").format('DD MM YYYY');
alert(a)
// This should be Invalid, but its valid. (Month is 24)
Version : Moment.js 2.10.3
You should pass the format as an argument:
moment("24 12 1995", "DD MM YYYY");
What .format
function does is formatting the output.
So you can do:
var format = "DD MM YYYY";
var date = moment("24 12 1995", format);
alert(date.format(format));
You could use the second parameter
moment("24 12 1995","DD MM YYYY");
to specify the format of the input string.
Then you can format it any way you want :
moment("24 12 1995","DD MM YYYY").format('MM DD YYYY')
moment("24 12 1995","DD MM YYYY").format('DD MM YYYY')
moment("24 12 1995","DD MM YYYY").format('ddd M YYYY')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With