① 소스 내용

<?xml version="1.0" encoding="EUC-KR" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />

<title>날짜 (DATE)</title>

        <script type="text/javascript">

               var no;

              

               function init() {

                       var target = document.getElementById("target");

                       var t = new Date();

                       target.innerHTML = t.getFullYear() + "-" + (t.getMonth()+1) + "-" + t.getDate()

                                                             + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();

                       // target.innerHTML = new Date();

                       // setInterval window객체에 있는 메소드이다.

                       // 원래는 window.setInterval이지만 window 생략가능하다.

                       no = setInterval(setTime, 1000); // setInterval 실행되면 고유번호가 no 대입

                       //alert(no);

               }

               function setTime() {

                       var target = document.getElementById("target");

                       var t = new Date();

                       target.innerHTML = t.getFullYear() + "-" + (t.getMonth()+1) + "-" + t.getDate()

                                                            + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();

                      

                       // 2012-09-11 16:14:00 식으로 출력

                      

               }

</script>

</head>

<body onload="init();">

        <!--

                onload : body 만들어지고 난뒤에 실행

                >> 첫화면에서 어떤 이벤트가 일어나게 하고 싶을경우

         -->

        <input type="button" value="멈춰라" onclick="clearInterval(no);" />

        <input type="button" value="다시시작!" onclick="init();" />

        <div id="target"></div>

</body>

</html>


② 실행 화면

날짜 (DATE)



블로그 이미지

모데스티

,