javascript日期时间比较(网上找的)
<html>
<head>
<script type="text/javascript">
function change()
{
var pattern=/^ *(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}) *$/;
var outcome1=pattern.exec(str.value);
var outcome2=pattern.exec(end.value);
if (outcome1 && outcome2)
{
var result = compare2(outcome1[1], outcome2[1]);
if (result == 0)
{
result = compare2(outcome1[2], outcome2[2]);
if (result == 0)
{
result = compare2(outcome1[3], outcome2[3]);
if (result == 0)
{
result = compare2(outcome1[4], outcome2[4]);
if (result == 0)
{
result = compare2(outcome1[5], outcome2[5]);
}
}
}
}
if (result == 0)
alert("same date");
else if (result < 0)
alert("str < end");
else
alert("str > end");
}
function compare2(va1, va2)
{
if (va1 == va2)
return 0;
else if (va1 > va2)
return 1;
else
return -1;
}
}
</script>
</head>
<body>
<input type="text" name="str" />
<input type="text" name="end" />
<input type="submit" onclick="change()" />
</body>
</html>