時間を表示する単純な JavaScript コードを作成しようとしましたが、配列を設定して currentDay にアタッチすると、「NaN」と表示されます。=]コードは次のとおりです。
function updateTime(){
var currentTime = new Date();
var Wordday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
var hours = currentTime.getHours()
if ( hours == 0 ) {
hours = "0" ? 12 : hours
};
var minutes = currentTime.getMinutes();
if (minutes < 10){
minutes = "0" + minutes;
};
var seconds = currentTime.getSeconds();
if (seconds < 10){
seconds = "0" + seconds;
};
var day = currentTime.getDay();
var t_str = + Wordday[day] + " " + hours + ":" + minutes + ":" + seconds + " ";
if(hours > 11){
t_str += "AM";
} else {
t_str += "PM";
};
document.getElementById('time_span').innerHTML = t_str;
}
setInterval(updateTime, 1000);