-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateAndTime.js
43 lines (31 loc) · 874 Bytes
/
DateAndTime.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
/*
Write a JavaScript program to display the current day and time
*/
const date = new Date();
const day = date.getDay();
const daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
console.log(`Today is: ${daylist[day]}.`);
let hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
let prepand = (hour >= 12) ? "PM" : "AM";
hour = (hour >= 12) ? hour - 12 : hour;
if(hour === 0 && prepand === "PM") {
if(minute === 0 && prepand === "PM") {
hour = 12;
prepand = "Noon";
}
}else {
hour = 12;
prepand = "PM";
}
if(hour === 0 && prepand === "AM") {
if(minute === 0 && second === 0) {
hour = 12;
prepand = "Midnight";
}
}else {
hour = 12;
prepand = "AM";
}
console.log(`Current time: ${hour} ${prepand} : ${minute} : ${second}`);