Moonstar Moonstar - 2 months ago 5
Java Question

Check whether the Date exists (30th / 31th day)

how to check whether the 30 or 31th day of a month does exist or not.

31.09.2016 doesn't exist but will be shown as 01.10.2016 in Java and Javascript. Even with the correct locales etc. Any solutions in javascript or java is welcome since an ajax request can solve this as well.

Thanks in advance

Answer

I think you should use the momentjs library for any kind of date manipulation in javascript: MomentJS

var date = moment('31.09.2016','DD.MM.YYYY');
console.log(date.isValid()); // This will print false in case of an invalid date

Edit: Created a plunker so you can try it out: plunker example . Check the javascript console

Comments