Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter14 : 함수문제 본문

WEB.JS/04.함수_JS

chapter14 : 함수문제

GAWON 2023. 5. 19. 17:36
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

</head>
<body>
<h1 id="clock">0000-00-00 00:00:00</h1>
<input type="button" value="현재시간 출력!" onclick= "start();">
<input type="button" value="정지"onclick= "stop();">
<script type="text/javascript">

```
var clock = document.getElementById("clock")
function watch() {

	 var date = new Date();
	 var year = date.getFullYear();
	 var month = date.getMonth() + 1;
	 var d = date.getDate();
	 var hour = date.getHours();
	 var minute = date.getMinutes();
	 var seconds = date.getSeconds();
	 var timer;

	 if(seconds < 10){
		 seconds = "0" + seconds;
	 }
	 if(minute < 10){
		 minute = "0" + minute;
	 }
	 if(hour < 10){
		 hour = "0" + hour;
	 }
	 if(d < 10 ){
		 d = "0" + d;
	 }
	 if(month < 10){
		 month = "0" + month;
	 }

	clock.innerHTML = `${year}-${month}-${d}  ${hour}:${minute}:${seconds}`;

}

//setInterval(watch,1000);
//watch();

var id2;
function start(){
	 id2 = setInterval(watch ,1000);
}
function stop(){
	     clearInterval(id2);
	 }

```

</script>
</body>
</html>

'WEB.JS > 04.함수_JS' 카테고리의 다른 글

chapter13 : 함수문제  (0) 2023.05.19
chapter12 : 함수문제  (0) 2023.05.19
chapter11 : 함수문제  (0) 2023.05.19
chapter10 : 타이머_내장함수  (0) 2023.05.19
chapter09 : 재귀함수  (0) 2023.05.19