-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
46 lines (44 loc) · 1.4 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
//let target the elements
let time = document.querySelector('.time');
let date = document.querySelector('.date');
//let now get the current date information
let currentTime = new Date();
//let get what we need from the current time
let weekday = currentTime.toLocaleString('default',{
weekday: 'long'
});
let month = currentTime.toLocaleString('default',{
month: 'short'
});
let monthDate = currentTime.getDate();
let hours = currentTime.getHours();
let minutes = currentTime.getMinutes();
// call a function to implement the date information to the website.
window.addEventListener('load',()=>{
date.innerText = `${weekday}, ${month} ${monthDate}`;
time.innerText = `${hours}:${minutes}`
})
// let make an updating program
let updateTime = setInterval(()=>{
//let now get the current date information
let currentTime = new Date();
//let get what we need from the current time
let weekday = currentTime.toLocaleString('default',{
weekday: 'long'
});
let month = currentTime.toLocaleString('default',{
month: 'short'
});
let monthDate = currentTime.getDate();
let hours = currentTime.getHours();
if (hours<10) {
hours= "0"+hours;
}
let minutes = currentTime.getMinutes();
if (minutes<10) {
minutes= "0"+minutes;
}
// call a function to implement the date information to the website.
date.innerText = `${weekday}, ${month} ${monthDate}`;
time.innerText = `${hours}:${minutes}`;
},1000);