html代碼:
<div class="time">
<form name=timeForm>
<input type="hidden" name=times value="{$stime}">
<span>距離結束僅剩:</span><span id="date"></span><span class="white14b">天</span><span id="time"></span>
</form>
</div>
JS代碼:
var now = new Date();
function GetServerTime()
{
var a = document.timeForm.times.value;
var urodz = new Date("a");
now.setTime(now.getTime()+250);
days = (urodz - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (urodz - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (urodz - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
document.getElementById("date").innerHTML = daysRound;
document.getElementById("time").innerHTML = hoursRound + "時" + minutesRound + "分" + secondsRound + "秒";
}
setInterval("GetServerTime()",250);
js 時間Date
js中獲取時間new Date()
js中的New Date獲取各種時間
----------------------同志你好,我是CSDN問答機器人小N,奉組織之命為你提供參考答案,編程尚未成功,同志仍需努力!