-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (31 loc) · 1.19 KB
/
script.js
File metadata and controls
39 lines (31 loc) · 1.19 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
import { timeZonesList } from "./local.js";
document.addEventListener('DOMContentLoaded', onPageLoad);
let dateContainer = document.querySelector('.show-date');
let timeZone = '';
const comboBox = document.querySelector('#localelist');
function onPageLoad() {
loadLocalesInComboBox();
let selectedOption = comboBox.options[comboBox.selectedIndex];
timeZone = comboBox.value;
comboBox.addEventListener('change',handleComboBox);
setInterval(displayLocalTime,1000);
}
function handleComboBox(){
let selectedOption = comboBox.options[comboBox.selectedIndex];
timeZone = comboBox.value;
}
function displayLocalTime(){
const date = new Date();
dateContainer.innerHTML = date.toLocaleString('en-IN',{timeZone:timeZone , hour:'2-digit',minute:'2-digit',second:'2-digit'});
}
function loadLocalesInComboBox() {
const timeZoneKeys = Object.keys(timeZonesList);
timeZoneKeys.sort();
timeZoneKeys.forEach((tz) => {
const label = timeZonesList[tz];
let newOption = new Option(label.trim(), tz.trim());
comboBox.add(newOption, undefined);
});
//Default time
comboBox.value = 'Asia/Kolkata';
}