-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (38 loc) · 1.26 KB
/
app.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
const days = [
'Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday',
'Saturday'
];
const months = [
'January', 'February', 'March',
'April', 'May', 'June', 'July',
'August', 'September', 'October',
'November', 'December'
];
const dateElement = document.querySelector('.date');
const timeElement = document.querySelector('.time');
const createDateAndTime = () => {
const today = new Date();
const date = today.getDate();
const day = today.getDay();
const month = today.getMonth();
const year = today.getFullYear();
const hours = today.getHours();
const minutes = today.getMinutes();
const seconds = today.getSeconds();
const noon = (hours < 12) ? "AM" : "PM";
const hoursInTwelveHoursFormat = (hours > 12) ? (hours - 12) : hours;
const dateTemplate = `
<span>${date}</span>
<span>${days[day]}</span>,
<span>${months[month]}</span>,
<span>${year}</span>!
`;
const timeTemplate = `
<span>${hoursInTwelveHoursFormat}</span>:<span>${minutes}</span>:<span>${seconds}</span> <span>${noon}</span>
`;
dateElement.innerHTML = dateTemplate;
timeElement.innerHTML = timeTemplate;
};
const oneSecond = 1000;
setInterval(createDateAndTime, oneSecond);