Is this a good way to check for a valid date in JavaScript?

后端 未结 3 1301
别跟我提以往
别跟我提以往 2021-01-15 09:07

Please correct or explain how my over-simplification is incorrect as I am not a JavaScript expert.

But I just need to know if an object is a valid date. This will o

3条回答
  •  旧时难觅i
    2021-01-15 09:44

    new Date() doesn't throw an exception if month>12 for example, you can use Date.parse() and test the returned value with isNaN()

提交回复
热议问题