Check if date is a valid one

前端 未结 9 659
再見小時候
再見小時候 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:04

    var date = moment('2016-10-19', 'DD-MM-YYYY', true);

    You should add a third argument when invoking moment that enforces strict parsing. Here is the relevant portion of the moment documentation http://momentjs.com/docs/#/parsing/string-format/ It is near the end of the section.

提交回复
热议问题