const isValidDate = function(date) {
return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date));
}
function isValidDate(dateObject){
return new Date(dateObject).toString() !== 'Invalid Date';
}
const isDate = (str) => {
return (new Date(str) !== "Invalid Date") && !isNaN(new Date(str));
}
console.log(isDate('2020-01-01'))
console.log(isDate('abc'))
var date_regex = /^(0[1-9]|1[0-2])/(0[1-9]|1d|2d|3[01])/(19|20)d{2}$/;
if (!(date_regex.test(testDate))) {
return false;
}
const isDateValid = (...val) => !Number.isNaN(new Date(...val).valueOf());
isDateValid('December 17, 1995 03:24:00'); // true
isDateValid('1995-12-17T03:24:00'); // true
isDateValid('1995-12-17 T03:24:00'); // false
isDateValid('Duck'); // false
isDateValid(1995, 11, 17); // true
isDateValid(1995, 11, 17, 'Duck'); // false
isDateValid({}); // false