-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssignment1_1.html
More file actions
41 lines (34 loc) · 1.35 KB
/
Assignment1_1.html
File metadata and controls
41 lines (34 loc) · 1.35 KB
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
<!DOCTYPE html>
<html>
<body>
<h2>DAY</h2>
<script>
const days = ["null","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
const d = new Date();
document.write("Today is : "+ days[d.getDay()]);
</script>
<h2>Time</h2>
<button onclick="myFunction()">
Click here to know Time </button>
<p id="change"></p>
<script>
// JavaScript function to
// Display 12 hour format
function myFunction() {
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var sec = date.getSeconds();
// Check whether AM or PM
var newformat = hours >= 12 ? 'PM' : 'AM';
// Find current hour in AM-PM Format
hours = hours % 12;
// To display "0" as "12"
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0' + minutes : minutes;
document.getElementById("change").innerHTML ="Current time is : " +
hours +" "+ newformat+ ' : ' + minutes + ' : ' +sec ;
}
</script>
</body>
</html>