<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8" />
<script >
function DateSetDef(dataString, flag, nullFlag,date)
{
// var newFullDate="2013-08-01 00:00:00:000";
// alert(newFullDate.substring(0,13));
//re = /^[0-9]{4}[-]{1}[0]{1}[1-9]{1}$|^[0-9]{4}[-]{1}[1]{1}[0-2]{1}/; // 小时格式 "yyyy-MM-dd hh";
re=/(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)/
re=/^[0]{1}[1-9]{1}$|^[1-6]{1}[0-9]{1}$/
var str="2013-08-01 12";
alert(str.substring(11,13));
alert(re.test(str.substring(11,13)));
}
</script>
</head>
<body>
<div >
<input type="button" value="for date format test" onclick="DateSetDef()"></input>
</div>
<footer>
<h2>HTML5</h2>
</footer>
</body>
</html>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)