Js-現在の時間を取得します.
1025 ワード
<div id="Time"/>
<script type="text/javascript">
getDate()
function getDate() {
var timezone = 8;
var offset_GMT = new Date().getTimezoneOffset();
var nowDate = new Date().getTime();
var today = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000);
var date = today.getFullYear() + "-" + twoDigits(today.getMonth() + 1) + "-" + twoDigits(today.getDate());
var time = twoDigits(today.getHours()) + ":" + twoDigits(today.getMinutes()) + ":" + twoDigits(today.getSeconds());
document.getElementById("Time").innerHTML=' :' + date + ' ' + time;
}
function twoDigits(val) {
if (val < 10) return "0" + val;
return val;
}
setInterval(getDate, 1000);
</script>
</code></pre>
<p> </p>
</div>
</div>
</div>
</div>