火狐下js的日期比较的方法

function tab(date1,date2){

    var oDate1 = new Date(date1);

    var oDate2 = new Date(date2);

    if(oDate1.getTime() > oDate2.getTime()){

        console.log('第一个大');

    } else {

        console.log('第二个大');

    }

}

tab('2015-10-10','2015-10-11');

-需要换成/火狐才支持
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8 />
<title>Page Title</title>
<script>
window.onload = function()
{
var reg = /^\s*|\s*$/g;
var t1 = document.getElementById("t1").value.replace(reg, "");
var t2 = document.getElementById("t2").value.replace(reg, "");
reg = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d*)$/;
if (!reg.test(t1) || !reg.test(t2)) {
throw new Error("Date Format is Error !");
return;
}
var d1 = new Date(t1.replace(reg, "$1"), parseInt(t1.replace(reg, "$2")) - 1, t1.replace(reg, "$3"));
d1.setHours(t1.replace(reg, "$4"), t1.replace(reg, "$5"), t1.replace(reg, "$6"));
var d2 = new Date(t2.replace(reg, "$1"), parseInt(t2.replace(reg, "$2")) - 1, t2.replace(reg, "$3"));
d2.setHours(t2.replace(reg, "$4"), t2.replace(reg, "$5"), t2.replace(reg, "$6"));
if (d1 > d2) {
alert("error");
}
}
</script>
</head>
<body>
<input type="text" id="t1" value="2014-03-02 12:00:01" />
<input type="text" id="t2" value="2014-03-02 12:00:00" />
</body>
</html>
上一篇:【总结整理】javascript进阶学习(慕课网)


下一篇:NoSQL和MongoDB