ページのリアルタイム更新時間のJSインスタンスコード
2095 ワード
function startTime() {
var today = new Date(); //
var yyyy = today.getFullYear(); // getFullYear()
var MM = today.getMonth() + 1; // getMonth()
var dd = today.getDate(); // getDate()
var hh = today.getHours(); // getHours
var mm = today.getMinutes(); // getMinutes
var ss = today.getSeconds(); // getSeconds
// 10, 0, 3 20 9 , 15:20:09
MM = checkTime(MM);
dd = checkTime(dd);
mm = checkTime(mm);
ss = checkTime(ss);
var day; // (getDay() )
if (today.getDay() == 0) day = " "
if (today.getDay() == 1) day = " "
if (today.getDay() == 2) day = " "
if (today.getDay() == 3) day = " "
if (today.getDay() == 4) day = " "
if (today.getDay() == 5) day = " "
if (today.getDay() == 6) day = " "
document.getElementById('nowDateTimeSpan').innerHTML = yyyy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss + " " + day;
setTimeout('startTime()', 1000); // startTime()
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
呼び出し:現在の時間: