-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedDigitalClock.html
More file actions
174 lines (151 loc) · 5.42 KB
/
AdvancedDigitalClock.html
File metadata and controls
174 lines (151 loc) · 5.42 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Digital Clock</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', sans-serif;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(45deg, #1a1a1a, #2d2d2d);
overflow: hidden;
}
.clock-container {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 2rem 3rem;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.time {
font-size: 4.5rem;
font-weight: 300;
color: #fff;
text-align: center;
letter-spacing: 2px;
text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}
.seconds {
font-size: 1.5rem;
opacity: 0.7;
vertical-align: top;
}
.date {
color: #fff;
font-size: 1.2rem;
text-align: center;
margin-top: 1rem;
opacity: 0.8;
}
.controls {
margin-top: 2rem;
display: flex;
gap: 1rem;
justify-content: center;
flex-wrap: wrap;
}
.btn {
padding: 0.6rem 1.2rem;
border: none;
border-radius: 25px;
background: rgba(255, 255, 255, 0.1);
color: #fff;
cursor: pointer;
transition: all 0.3s ease;
font-size: 0.9rem;
}
.btn:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
.btn.active {
background: #4CAF50;
}
@keyframes gradient {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
@media (max-width: 480px) {
.time { font-size: 3rem; }
.seconds { font-size: 1rem; }
.clock-container { padding: 1.5rem 2rem; }
}
</style>
</head>
<body>
<div class="clock-container">
<div class="time" id="time">00:00<span class="seconds" id="seconds">:00</span></div>
<div class="date" id="date">Monday, January 1</div>
<div class="controls">
<button class="btn" id="toggleFormat">24H</button>
<button class="btn active" id="toggleSeconds">Seconds</button>
<button class="btn active" id="toggleDate">Date</button>
</div>
</div>
<script>
const timeElement = document.getElementById('time');
const secondsElement = document.getElementById('seconds');
const dateElement = document.getElementById('date');
const toggleFormatBtn = document.getElementById('toggleFormat');
const toggleSecondsBtn = document.getElementById('toggleSeconds');
const toggleDateBtn = document.getElementById('toggleDate');
let is24Hour = true;
let showSeconds = true;
let showDate = true;
function updateClock() {
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
let period = '';
if (!is24Hour) {
period = hours >= 12 ? ' PM' : ' AM';
hours = hours % 12 || 12;
}
hours = hours.toString().padStart(2, '0');
minutes = minutes.toString().padStart(2, '0');
seconds = seconds.toString().padStart(2, '0');
timeElement.innerHTML = `${hours}:${minutes}${showSeconds ? '<span class="seconds">:' + seconds + '</span>' : ''}${period}`;
if (showDate) {
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
dateElement.textContent = `${days[now.getDay()]}, ${months[now.getMonth()]} ${now.getDate()}`;
dateElement.style.display = 'block';
} else {
dateElement.style.display = 'none';
}
secondsElement.style.display = showSeconds ? 'inline' : 'none';
}
toggleFormatBtn.addEventListener('click', () => {
is24Hour = !is24Hour;
toggleFormatBtn.textContent = is24Hour ? '24H' : '12H';
toggleFormatBtn.classList.toggle('active');
updateClock();
});
toggleSecondsBtn.addEventListener('click', () => {
showSeconds = !showSeconds;
toggleSecondsBtn.classList.toggle('active');
updateClock();
});
toggleDateBtn.addEventListener('click', () => {
showDate = !showDate;
toggleDateBtn.classList.toggle('active');
updateClock();
});
// Update clock every second
setInterval(updateClock, 1000);
updateClock(); // Initial call
</script>
</body>
</html>