恩....你試試
<span id="Check_Txt" style="color:red">時間計數:<span id="Check_i">0小時0分0秒</span></span>
<script type="text/javascript">
var SetMinute = 0;
function Check_Time() {
SetMinute += 1;
var Check_i = document.getElementById("Check_i");
var Cal_Hour = Math.floor(SetMinute / 3600);
var Cal_Minute = Math.floor(Math.floor(SetMinute % 3600) / 60);
var Cal_Second = SetMinute % 60;
Check_i.innerHTML = Cal_Hour + "小時" + Cal_Minute + "分" + Cal_Second + "秒";
}
var mm = window.setInterval("Check_Time()", 1000);
</script>
這樣?不過我猜我的code只能處理24小時,不想算數學的寫法。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="time"></div>
</body>
</html>
<script>
var temp = new Date();
function checktime(){
var now = new Date(),
diff = new Date(now -temp);
document.getElementById("time").innerText = diff.Myformat();
}
Date.prototype.Myformat = function(){
return ("0"+ this.getUTCHours()).slice(-2)+":"+("0"+this.getUTCMinutes()).slice(-2)+":"+("0"+this.getUTCSeconds()).slice(-2)
}
setInterval(checktime, 1000);
</script>