Check if date is a valid one

前端 未结 9 647
再見小時候
再見小時候 2020-12-13 11:52

Following is the scenario:

I have a String date and a date format which is different. Ex.:
date: 2016-10-19
dateFormat: \"DD-MM-YYYY\".

9条回答
  •  爱一瞬间的悲伤
    2020-12-13 12:20

    I use moment along with new Date to handle cases of undefined data values:

    const date = moment(new Date("2016-10-19"));

    because of: moment(undefined).isValid() == true

    where as the better way: moment(new Date(undefined)).isValid() == false

提交回复
热议问题