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

本文介绍了一段JavaScript代码实现倒计时功能,并在倒计时结束后自动跳转至拍卖结果页面的过程。

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了。

转载于:https://www.cnblogs.com/wuchao/archive/2012/08/30/2663822.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值