js时间距离 倒计时用到

 var endtime = "2015-12-31 23:59:59"
        //获得当前时间
        var d = new Date();
        var s = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

        var d1 = new Date(endtime.replace(/-/g, "/"));
        var d2 = new Date(s.replace(/-/g, "/"));
        if (Date.parse(d1) - Date.parse(d2) > 0) {
            //计算当前时间距结束时间多少秒
            var miao = (Date.parse(d1) - Date.parse(d2)) / 1000;
            //计算相差多少天
            var tian = parseInt(miao / 86400);//获得天数
            var shi = parseInt(miao / 3600 - tian * 24);//获得小时数
            var fen = parseInt(miao / 60 - (shi * 60 + tian * 1440));//获得分钟数

            var timeed = tian + "天" + shi + "时" + fen + "分";
        }

 

posted @ 2015-11-06 14:41  VisibleIsFalse  阅读(470)  评论(0编辑  收藏  举报