How to check if a string is a legal “dd/mm/yyyy” date?

前端 未结 7 1989
遥遥无期
遥遥无期 2020-12-01 15:05

Given a string str, how could I check if it is in the dd/mm/yyyy format and contains a legal date ?

Some examples:

bla bla          


        
7条回答
  •  盖世英雄少女心
    2020-12-01 15:43

    Recent discovery: You can use date.js lib, it adds function Date.parseExact so you can just do Date.parseExact(dateString,"dd/MM/yyyy"). It fails when month is 00, but its still usefull.

提交回复
热议问题