This repository was archived by the owner on Mar 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti-timezone-clock.html
More file actions
419 lines (362 loc) · 12.2 KB
/
multi-timezone-clock.html
File metadata and controls
419 lines (362 loc) · 12.2 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi-Timezone Digital Clock</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Courier New', monospace;
background: linear-gradient(135deg, #1e3c72, #2a5298);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
max-width: 1200px;
width: 100%;
}
.header {
text-align: center;
margin-bottom: 40px;
}
.header h1 {
color: white;
font-size: 2.5rem;
font-weight: bold;
text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.4);
margin-bottom: 10px;
letter-spacing: -0.5px;
line-height: 1.2;
}
.header p {
color: #b8d4f0;
font-size: 1.1rem;
line-height: 1.6;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}
.clocks-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.clock-panel {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 15px;
padding: 25px;
text-align: center;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.clock-panel:hover {
transform: translateY(-5px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
background: rgba(255, 255, 255, 0.15);
border-color: rgba(255, 255, 255, 0.3);
}
.timezone-name {
color: #ffffff;
font-size: 1.3rem;
font-weight: bold;
margin-bottom: 5px;
text-transform: uppercase;
letter-spacing: 1px;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}
.timezone-location {
color: #b8d4f0;
font-size: 0.9rem;
margin-bottom: 20px;
font-style: italic;
opacity: 0.9;
}
.time-display {
color: #00ff88;
font-size: 2.2rem;
font-weight: bold;
margin-bottom: 10px;
text-shadow: 0 0 15px rgba(0, 255, 136, 0.4), 0 0 30px rgba(0, 255, 136, 0.2);
font-family: 'Courier New', monospace;
letter-spacing: 2px;
}
.date-display {
color: #ffffff;
font-size: 1rem;
margin-bottom: 5px;
font-weight: 500;
}
.day-display {
color: #b8d4f0;
font-size: 0.9rem;
font-weight: 500;
}
.footer {
text-align: center;
color: #b8d4f0;
font-size: 0.9rem;
margin-top: 30px;
opacity: 0.9;
font-weight: 500;
}
/* Responsive design */
@media (max-width: 768px) {
body {
padding: 15px;
}
.container {
padding: 0;
}
.header {
margin-bottom: 30px;
padding: 15px;
background: rgba(0, 0, 0, 0.2);
border-radius: 15px;
backdrop-filter: blur(10px);
}
.header h1 {
font-size: 2rem;
letter-spacing: 0.5px;
line-height: 1.3;
}
.header p {
font-size: 1rem;
line-height: 1.5;
}
.clocks-grid {
grid-template-columns: 1fr;
gap: 15px;
}
.clock-panel {
padding: 22px 18px;
border-radius: 12px;
}
.timezone-name {
font-size: 1.15rem;
margin-bottom: 4px;
}
.timezone-location {
font-size: 0.85rem;
margin-bottom: 18px;
}
.time-display {
font-size: 1.9rem;
margin-bottom: 8px;
}
.date-display {
font-size: 0.95rem;
margin-bottom: 4px;
}
.day-display {
font-size: 0.85rem;
}
.footer {
margin-top: 25px;
padding: 15px;
background: rgba(0, 0, 0, 0.2);
border-radius: 12px;
backdrop-filter: blur(10px);
}
}
@media (max-width: 480px) {
body {
padding: 10px;
}
.header {
padding: 12px;
margin-bottom: 20px;
}
.header h1 {
font-size: 1.75rem;
line-height: 1.25;
}
.header p {
font-size: 0.9rem;
}
.clock-panel {
padding: 20px 15px;
border-radius: 12px;
}
.timezone-name {
font-size: 1.05rem;
}
.timezone-location {
font-size: 0.8rem;
margin-bottom: 15px;
}
.time-display {
font-size: 1.7rem;
letter-spacing: 1px;
}
.date-display {
font-size: 0.9rem;
}
.day-display {
font-size: 0.8rem;
}
.footer {
margin-top: 20px;
padding: 12px;
font-size: 0.85rem;
}
}
/* Animation for time update */
.time-update {
animation: pulse 0.5s ease-in-out;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.02); }
100% { transform: scale(1); }
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Multi-Timezone Digital Clock</h1>
<p>Real-time clock displaying current time across different time zones</p>
</div>
<div class="clocks-grid" id="clocksGrid">
<!-- Clock panels will be dynamically generated here -->
</div>
<div class="footer">
<p>Updates every second • Powered by JavaScript</p>
</div>
</div>
<script>
// Configuration: Time zones to display
// To add or remove time zones, simply modify this array
const timeZones = [
{
name: 'UTC',
location: 'Coordinated Universal Time',
timezone: 'UTC'
},
{
name: 'Oman',
location: 'Muscat, Oman',
timezone: 'Asia/Muscat'
},
{
name: 'New York',
location: 'New York, USA',
timezone: 'America/New_York'
},
{
name: 'London',
location: 'London, UK',
timezone: 'Europe/London'
},
{
name: 'Tokyo',
location: 'Tokyo, Japan',
timezone: 'Asia/Tokyo'
}
];
// Function to create clock panels
function createClockPanels() {
const clocksGrid = document.getElementById('clocksGrid');
clocksGrid.innerHTML = '';
timeZones.forEach((tz, index) => {
const clockPanel = document.createElement('div');
clockPanel.className = 'clock-panel';
clockPanel.innerHTML = `
<div class="timezone-name">${tz.name}</div>
<div class="timezone-location">${tz.location}</div>
<div class="time-display" id="time-${index}">00:00:00</div>
<div class="date-display" id="date-${index}">Loading...</div>
<div class="day-display" id="day-${index}">Loading...</div>
`;
clocksGrid.appendChild(clockPanel);
});
}
// Function to format time with leading zeros
function formatTime(date) {
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}
// Function to format date
function formatDate(date) {
const options = {
year: 'numeric',
month: 'long',
day: 'numeric'
};
return date.toLocaleDateString('en-US', options);
}
// Function to get day of week
function formatDay(date) {
const options = { weekday: 'long' };
return date.toLocaleDateString('en-US', options);
}
// Function to update all clocks
function updateClocks() {
timeZones.forEach((tz, index) => {
try {
// Create date object for the specific timezone
const now = new Date();
const timeInZone = new Date(now.toLocaleString("en-US", {timeZone: tz.timezone}));
// Get elements
const timeElement = document.getElementById(`time-${index}`);
const dateElement = document.getElementById(`date-${index}`);
const dayElement = document.getElementById(`day-${index}`);
if (timeElement && dateElement && dayElement) {
// Update time
const formattedTime = formatTime(timeInZone);
if (timeElement.textContent !== formattedTime) {
timeElement.textContent = formattedTime;
timeElement.classList.add('time-update');
setTimeout(() => {
timeElement.classList.remove('time-update');
}, 500);
}
// Update date and day
dateElement.textContent = formatDate(timeInZone);
dayElement.textContent = formatDay(timeInZone);
}
} catch (error) {
console.error(`Error updating clock for ${tz.name}:`, error);
// Fallback to local time if timezone is not supported
const timeElement = document.getElementById(`time-${index}`);
const dateElement = document.getElementById(`date-${index}`);
const dayElement = document.getElementById(`day-${index}`);
if (timeElement && dateElement && dayElement) {
const now = new Date();
timeElement.textContent = formatTime(now);
dateElement.textContent = formatDate(now);
dayElement.textContent = formatDay(now);
}
}
});
}
// Initialize the clocks
function initializeClocks() {
createClockPanels();
updateClocks();
// Update every second
setInterval(updateClocks, 1000);
}
// Start the clocks when the page loads
document.addEventListener('DOMContentLoaded', initializeClocks);
// Handle visibility change to ensure clocks continue updating
document.addEventListener('visibilitychange', function() {
if (!document.hidden) {
updateClocks();
}
});
</script>
</body>
</html>