-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClock.html
39 lines (32 loc) · 1.39 KB
/
Clock.html
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
<script>
function printClock() {
var clock = document.getElementById("clock"); // 출력할 장소 선택
var currentDate = new Date(); // 현재시간
var calendar = currentDate.getFullYear() + "-" + (currentDate.getMonth()+1) + "-" + currentDate.getDate() // 현재 날짜
var amPm = 'AM'; // 초기값 AM
var currentHours = addZeros(currentDate.getHours(),2);
var currentMinute = addZeros(currentDate.getMinutes() ,2);
var currentSeconds = addZeros(currentDate.getSeconds(),2);
if(currentHours >= 12){ // 시간이 12보다 클 때 PM으로 세팅, 12를 빼줌
amPm = 'PM';
currentHours = addZeros(currentHours - 12,2);
}
clock.innerHTML = currentHours+":"+currentMinute+":"+currentSeconds +" <span style='font-size:50px;'>"+ amPm+"</span>"; //날짜를 출력해 줌
setTimeout("printClock()",1000); // 1초마다 printClock() 함수 호출
}
function addZeros(num, digit) { // 자릿수 맞춰주기
var zero = '';
num = num.toString();
if (num.length < digit) {
for (i = 0; i < digit - num.length; i++) {
zero += '0';
}
}
return zero + num;
}
</script>
<body>
<body onload="printClock()">
<div style="border:1px solid #dedede; width:600px; height:250px; line-height:250px; color:#666;font-size:100px; text-align:center;" id="clock">
</div>
</body>