↓実行結果
2000/00/00( ) 00:00:00
<script>
function clock(DOM) {
var yobi= new Array("日","月","火","水","木","金","土");
const timeText =
//20XX/MM/DD(W)
(new Date().getFullYear()) + "/"
+("0"+ (new Date().getMonth()+1)).slice(-2) + "/"
+("0"+ new Date().getDate() ).slice(-2) + "("
+(yobi[ new Date().getDay() ] ) + ")"
+" "
//時:分:秒
+("0"+new Date().getHours() ).slice(-2) + ":"
+("0"+new Date().getMinutes()).slice(-2) + ":"
+("0"+new Date().getSeconds()).slice(-2)
;
if(DOM){document.getElementById("viewClock").innerHTML = timeText;}
else{return timeText;}
}
window.onload = function(){clock("DOM"); console.log(clock());}
setInterval('clock("DOM")',1000);
</script>
<div id="viewClock">2000/00/00( ) 00:00:00</div>