Update index.html
Browse files- index.html +94 -17
index.html
CHANGED
@@ -1,19 +1,96 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<center>
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Time Calculator</title>
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
font-family: Arial, sans-serif;
|
11 |
+
}
|
12 |
+
input, button {
|
13 |
+
padding: 5px;
|
14 |
+
}
|
15 |
+
.new-time {
|
16 |
+
font-size: 24px;
|
17 |
+
background-color: yellow;
|
18 |
+
padding: 10px;
|
19 |
+
display: inline-block;
|
20 |
+
margin-top: 10px;
|
21 |
+
}
|
22 |
+
.title {
|
23 |
+
background-color: lightgreen;
|
24 |
+
display: inline-block;
|
25 |
+
padding: 5px;
|
26 |
+
}
|
27 |
+
</style>
|
28 |
+
</head>
|
29 |
+
<body>
|
30 |
+
|
31 |
+
<h1 class="title">Time Calculator</h1>
|
32 |
+
<p>Enter the initial time and the number of minutes to add:</p>
|
33 |
+
|
34 |
+
<label for="time">Time:</label>
|
35 |
+
<input type="time" id="time" value="03:45">
|
36 |
+
<label for="am_pm">AM/PM:</label>
|
37 |
+
<select id="am_pm">
|
38 |
+
<option value="am">AM</option>
|
39 |
+
<option value="pm">PM</option>
|
40 |
+
</select>
|
41 |
+
<br>
|
42 |
+
<label for="minutes">Minutes to add:</label>
|
43 |
+
<input type="number" id="minutes" value="20">
|
44 |
+
<br>
|
45 |
+
<button onclick="calculateNewTime()">Calculate New Time</button>
|
46 |
+
|
47 |
+
<p id="result"></p>
|
48 |
+
|
49 |
+
<script>
|
50 |
+
function calculateNewTime() {
|
51 |
+
const timeInput = document.getElementById("time").value;
|
52 |
+
const amPm = document.getElementById("am_pm").value;
|
53 |
+
const minutesToAdd = parseInt(document.getElementById("minutes").value);
|
54 |
+
|
55 |
+
let [hours, minutes] = timeInput.split(":").map(Number);
|
56 |
+
|
57 |
+
// Convert to 24-hour format
|
58 |
+
if (amPm === "pm" && hours !== 12) {
|
59 |
+
hours += 12;
|
60 |
+
} else if (amPm === "am" && hours === 12) {
|
61 |
+
hours = 0;
|
62 |
+
}
|
63 |
+
|
64 |
+
// Add the minutes
|
65 |
+
minutes += minutesToAdd;
|
66 |
+
|
67 |
+
// Handle minute overflow
|
68 |
+
if (minutes >= 60) {
|
69 |
+
hours += Math.floor(minutes / 60);
|
70 |
+
minutes = minutes % 60;
|
71 |
+
}
|
72 |
+
|
73 |
+
// Handle hour overflow
|
74 |
+
if (hours >= 24) {
|
75 |
+
hours = hours % 24;
|
76 |
+
}
|
77 |
+
|
78 |
+
// Convert back to 12-hour format
|
79 |
+
let newAmPm = "AM";
|
80 |
+
if (hours >= 12) {
|
81 |
+
newAmPm = "PM";
|
82 |
+
if (hours > 12) {
|
83 |
+
hours -= 12;
|
84 |
+
}
|
85 |
+
} else if (hours === 0) {
|
86 |
+
hours = 12;
|
87 |
+
}
|
88 |
+
|
89 |
+
const newTime = `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")} ${newAmPm}`;
|
90 |
+
document.getElementById("result").innerHTML = `<span class="new-time">New Time: ${newTime}</span>`;
|
91 |
+
}
|
92 |
+
</script>
|
93 |
+
|
94 |
+
</body>
|
95 |
+
</center>
|
96 |
</html>
|