forked from easysIT/doit_HTML-CSS-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent.html
More file actions
45 lines (42 loc) · 1.11 KB
/
current.html
File metadata and controls
45 lines (42 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>현재 시각</title>
<style>
* {
margin:0;
padding:0;
overflow:hidden;
}
#container{
display:flex;
justify-content:center;
align-items:center;
min-height:100vh;
}
p {
font-size:1.2em;
}
.display {
font-size:1.5em;
font-weight:bold;
color:blue;
}
</style>
</head>
<body>
<div id="container">
<p>현재 시각 <span id="current" class="display"></span></p>
</div>
<script>
setInterval(displayNow, 1000); // 1초마다 시간 계산 함수 실행
function displayNow() { // 시간 계산 함수
var now = new Date(); // Date 객체의 인스턴스를 만듦
var currentTime = now.toLocaleTimeString(); // toLocaleTmeString() 메서드를 사용해 지역에 맞는 시간을 가져옴
document.querySelector("#current").innerHTML = currentTime; // id="current" 인 요소에 현재 시간 표시
}
</script>
</body>
</html>