js时间转换+比较 Date.parse的兼容


var tip = setInterval("checkTime()", "10000");
    var temp = document.getElementById("hidden_endT").value;
    var datereturn = toDate(temp);
    function checkTime() {
        var myTime=Date();
        if (Date.parse(myTime) > datereturn) {
            clearInterval(tip);
            var auctionCode=document.getElementById("auctionCode").value;
            window.open("ResultAuction.aspx?auctionCode=" + auctionCode, "_self");
        }
    }
    function toDate(getTemp) {

        temp = getTemp.split(" ");
        var dateReturn = temp[0].split("-")[1] + "-" + temp[0].split("-")[2] + "-" + temp[0].split("-")[0] + " " + temp[1].split(":")[0] + ":" + temp[1].split(":")[1] + ":" + temp[1].split(":")[2];
        return Date.parse(dateReturn);
    }

 

比较的时间格式:2012-8-30 17:45:00

不兼容火狐浏览器         var dateReturn = temp[0].split("-")[1] + "/" + temp[0].split("-")[2] + "/" + temp[0].split("-")[0] + " " + temp[1].split(":")[0] + ":" + temp[1].split(":")[1] + ":" + temp[1].split(":")[2]; 将-改成/,就ok了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM