因为Javascript的日期格式判断可能因浏览器的版本有所不同,所以用正则判断会比较好,这里备注一个正则用来判断日期时间的格式:
^(?=d)(?:(?!(?:1582(?:.|-|/)10(?:.|-|/)(?:0?[5-9]|1[0-4]))|(?:1752(?:.|-|/)0?9(?:.|-|/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:dd)(?:[02468][048]|[13579][26]))D0?2D29)|(?:d{4}D(?!(?:0?[2469]|11)D31)(?!0?2(?:.|-|/)(?:29|30))))(d{4})([-/.])(0?d|1[012])2((?!00)[012]?d|3[01])(?:$|(?=x20d)x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]d){0,2}(?:x20[aApP][mM]))|(?:[01]d|2[0-3])(?::[0-5]d){1,2})?$
可以匹配的格式有:
1600-02-29 12:00:00 1900-02-28 2010-11-20 1900/02/28 2004-02-28 12:00:00