Answer the question
In order to leave comments, you need to log in
Where can I find sample programs in Java?
I want to see the practical application of any features.
Answer the question
In order to leave comments, you need to log in
Or another option without Date, but taking into account the leap year
https://jsfiddle.net/ProjectSoft/qqw8a8g3/
In the default example, the date of a non-leap year is 02/29/2015, which is an error.
let stringDate = '12 01 1999';
let parseDate = stringDate.split(' ');
let day = parseInt(parseDate[0], 10);
let month = parseInt(parseDate[1], 10) - 1;
let year = parseInt(parseDate[2], 10);
let d = new Date(year, month, day);
if (day == d.getDate() && month == d.getMonth() && year == d.getFullYear()) {
console.log(`${stringDate} - YES`);
} else {
console.error(`${stringDate} - NO`);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question