I have a JSON data containing dates (in mm/dd/yyyy format) which I am converting to Date
object using the Date
constructor like new Date(year, month, day)
. I want to return the date object only if the date string is valid. For e.g., for the string '12/08/1992', I should get Tue Dec 08 1992
as expected. But if I pass an invalid date like '15/08/1992' by doing new Date(1992, 14, 8)
(month is always n-1
for the Date
constructor), I get 'Mon Mar 08 1993', which is not as expected.
Is it possible to check somehow that the entered date is invalid? I can't use any libraries for this.