Web/Javascript

자바스크립트 현재시간 출력하기

qOOp 2008. 10. 21. 09:30
반응형

현재시간 출력

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=euc-kr" />

<title>현재시각</title>

<script>

function printTime() {

              var clock = document.getElementById("clock");            // 출력할 장소 선택

              var now = new Date();                                                  // 현재시간

              var nowTime = now.getFullYear() + "" + (now.getMonth()+1) + "" + now.getDate() + "" + now.getHours() + "" + now.getMinutes() + "" + now.getSeconds() + "";

              clock.innerHTML = nowTime;           // 현재시간을 출력

              setTimeout("printTime()",1000);         // setTimeout(“실행할함수”,시간) 시간은1초의 경우 1000

}

window.onload = function() {                         // 페이지가 로딩되면 실행

              printTime();

}

</script>

<body>

현재 <span id="clock"></span> 입니다<br />

</body>

</html>