Now is Tue Feb 02 2021 21:39:02
Now is Tue Feb 02 2021 21:39:03
Now is Tue Feb 02 2021 21:39:04
Now is Tue Feb 02 2021 21:39:05
Now is Tue Feb 02 2021 21:39:06
Now is Tue Feb 02 2021 21:39:07
Now is Tue Feb 02 2021 21:39:09
Now is Tue Feb 02 2021 21:39:10
Now is Tue Feb 02 2021 21:39:11
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<!--
- 이 요소는 3개의 class가 정의되어 있습니다.
-->
<script>
console.log("== Start")
// function printCurrentDate을 1초마다 실행하도록 setInterval
// 다만, 이후에 종료할 수 있도록 setInterval의 ID를 저장해놓음
function printCurrentDate() {
var currentDate = new Date();
console.log("Now is", currentDate.toString().substring(0, 25));
}
var setIntervalId = setInterval(printCurrentDate, 1000);
// 5000 milliseconds 후에
// setIntervalId를 멈춤
setTimeout(
() => {
clearInterval(setIntervalId)
console.log("== Complete")
},
5000
)
</script>
</body>
</html>
== Start
test.html:14 Now is Tue Feb 02 2021 21:49:14
test.html:14 Now is Tue Feb 02 2021 21:49:15
test.html:14 Now is Tue Feb 02 2021 21:49:16
test.html:14 Now is Tue Feb 02 2021 21:49:17
test.html:14 Now is Tue Feb 02 2021 21:49:18
== Complete
댓글남기기