-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (54 loc) · 1.74 KB
/
script.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const hour = document.querySelector("#hour");
const minute = document.querySelector("#min");
const second = document.querySelector("#sec");
const date = document.querySelector("#date");
const month = document.querySelector("#month");
const year = document.querySelector("#year");
const day = document.querySelector("#day");
let timeId = null;
function getCurrentFullDate() {
const currentDate = new Date();
return currentDate;
}
function getCurrentHour() {
const currentHour = getCurrentFullDate().getHours();
return currentHour;
}
function getCurrentMinute() {
const currentMinute = getCurrentFullDate().getMinutes();
return currentMinute;
}
function getCurrentSecond() {
const currentSec = getCurrentFullDate().getSeconds();
return currentSec;
}
function getCurrentDate() {
const todayDate = getCurrentFullDate().getDate();
return todayDate;
}
function getCurrentMonth() {
const currentMonth = getCurrentFullDate().getMonth();
const monthArray = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const month = monthArray[currentMonth];
return month;
}
function getCurrentYear() {
const currentYear = getCurrentFullDate().getFullYear();
return currentYear;
}
function getCurrentDay() {
const currentDay = getCurrentFullDate().getDay();
const dayArray = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
let day = dayArray[currentDay];
return day;
}
function updateTime() {
hour.textContent = getCurrentHour();
minute.textContent = getCurrentMinute();
second.textContent = getCurrentSecond();
date.textContent = getCurrentDate();
month.textContent = getCurrentMonth();
year.textContent = getCurrentYear();
day.textContent = getCurrentDay();
}
timeId = setInterval(updateTime, 1000);