【Javascript】リアルタイム日時を画面に表示する
<html>
<head><title>Javascript-リアルタイム日時を画面に表示する</title>
<script language="javascript">
<!--
function Watch() {
now = new Date();
year = now.getYear();
month = now.getMonth()+1;
day = now.getDate();
hour = now.getHours();
minute = now.getMinutes();
second = now.getSeconds();
if (year < 1000) { year += 1900 }
if (hour < 10) { hour = '0' + hour }
if (minute < 10) { minute = '0' + minute }
if (second < 10) { second = '0' + second }
divWatch.innerHTML = year+'年' + month + '月' + day + '日 ' + hour + ':' + minute + ':' + second;
setTimeout("Watch()",1000);
}
//-->
</script>
</head>
<body onLoad="Watch();">
<div id="divWatch" style="width_12em;background-color:yellow"></div>
</body>
</html>