-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS4.html
102 lines (86 loc) · 2.41 KB
/
JS4.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<head>
<title>Task 4 Javascript</title>
<style>
.container {
width: 100%;
max-width: 500px;
margin: 0 auto;
margin-top: 30px;
padding: 10px;
border: 1px solid rgba(0, 0, 0, 0.2);
border-width: auto;
}
.header-container {
text-align: center;
}
.main-container {
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
}
.showdate,
.showtime {
width: 50%;
text-align: center;
font-size: large;
padding: 10px;
border: 1px solid #cccccca4;
border-radius: 5px;
}
.footer-container {
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<header class="header-container">
<h1>Task-4</h1>
</header>
<main class="main-container">
<p>
<button type="button" onclick="updateDate()">Show Date</button>
</p>
<div id="showdate" class="showdate hidden" style="display:none">
<span>Date</span>
<span id="date"></span>
</div>
<p>
<button type="button" onclick="updateTime()">Show Time</button>
</p>
<div id="showtime" class="showtime hidden" style="display:none">
<span>Time</span>
<span id="time"></span>
<span>(GMT+05:30) Indian Standard Time (IST)</span>
</div>
</main>
</div>
<script>
function updateDate() {
// Get the current date.
var date = new Date();
// Format the date.
var formattedDate = date.toLocaleDateString();
// Update the HTML element with the formatted date.
document.getElementById("date").innerHTML = formattedDate;
// Show the date div and remove the hidden class.
document.getElementById("showdate").style.display = "block";
document.getElementById("showdate").classList.remove("hidden");
}
function updateTime() {
// Get the current time.
var time = new Date();
// Format the time.
var formattedTime = time.toLocaleTimeString();
// Update the HTML element with the formatted time.
document.getElementById("time").innerHTML = formattedTime;
// Show the time div and remove the hidden class.
document.getElementById("showtime").style.display = "block";
document.getElementById("showtime").classList.remove("hidden");
}
</script>
</body>
</html>