Skip to content

Commit 161f752

Browse files
date and time javascript program
1 parent 1e5805a commit 161f752

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

DateAndTime.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Displat current time and date</title>
8+
</head>
9+
10+
<body></body>
11+
12+
<script>
13+
14+
const date = new Date();
15+
16+
const day = date.getDay();
17+
const daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
18+
console.log(`Today is: ${daylist[day]}.`);
19+
20+
let hour = date.getHours();
21+
22+
const minute = date.getMinutes();
23+
24+
const second = date.getSeconds();
25+
26+
let prepand = (hour >= 12) ? "PM" : "AM";
27+
28+
hour = (hour >= 12) ? hour - 12 : hour;
29+
30+
if(hour === 0 && prepand === "PM") {
31+
if(minute === 0 && prepand === "PM") {
32+
hour = 12;
33+
prepand = "Noon";
34+
}
35+
}else {
36+
hour = 12;
37+
prepand = "PM";
38+
}
39+
40+
if(hour === 0 && prepand === "AM") {
41+
if(minute === 0 && second === 0) {
42+
hour = 12;
43+
prepand = "Midnight";
44+
}
45+
}else {
46+
hour = 12;
47+
prepand = "AM";
48+
}
49+
50+
console.log(`Current time: ${hour} ${prepand} : ${minute} : ${second}`);
51+
52+
</script>
53+
54+
</html>

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)