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