본문 바로가기
Program/Javascript

[javascript]현재 시간 실시간으로 보여주기

by 너부리공작소 2020. 2. 10.
반응형

[javascript]현재 시간 실시간으로 보여주기 

[javascript]현재 시간 실시간으로 보여주기

<script language="JavaScript">
function printTime() {
var clock = document.getElementById("clock");
var now = new Date();

clock.innerHTML = now.getFullYear() + "년 " +
(now.getMonth()+1) + "월 " +
now.getDate() + "일 " +
now.getHours() + "시 " +
now.getMinutes() + "분 " +
now.getSeconds() + "초";

setTimeout("printTime()", 1000);
}

window.onload = function() {
printTime();
};
</script>





<span id="clock"></span>

 

<script language="JavaScript">
function printTime() {
var clock = document.getElementById("clock");
var now = new Date();

clock.innerHTML = now.getFullYear() + "년 " +
(now.getMonth()+1) + "월 " +
now.getDate() + "일 " +
now.getHours() + "시 " +
now.getMinutes() + "분 " +
now.getSeconds() + "초";

setTimeout("printTime()", 1000);
}

window.onload = function() {
printTime();
};
</script>

 

 

<span id="clock"></span>

출처 : phpschool(https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_html&wr_id=174871)

 

반응형

댓글