倒计时 服务器时间 .NET js javascript

时间:2021-02-25 17:04:58

原文发布时间为:2011-02-07 —— 来源于本人的百度文章 [由搬家工具导入]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>服务器时间倒计时</title>
</head>
<body>
<span id="time"></span>
<script language="javascript">
    var SysSecond = 3600; //服务器距离现在的秒数,用aspx的服务器时间可以写成 var SysSecond =<%=Math.Floor((DateTime.Parse("2012/12/20 12:12:12") - DateTime.Now).TotalSeconds) %>
     function setRemainTime() {
        if (SysSecond > 0) {
            SysSecond = SysSecond - 1;
            var second = Math.floor(SysSecond % 60).toString();
            var minite = Math.floor((SysSecond / 60) % 60).toString();
            var hour = Math.floor((SysSecond / 3600) % 24).toString();
            var day = Math.floor((SysSecond / 3600) / 24).toString();
            document.getElementById("time").innerHTML=day + "天" + hour + "小时" + minite + "分" + second + "秒";
        } else {
            return;
        }
    }
    window.setInterval(setRemainTime, 1000);
</script>

</body>
</html>