-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 1.07 KB
/
index.js
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
const localEl = document.getElementById('local')
const estEl = document.getElementById('est');
const cstEl = document.getElementById('cst');
const mstEl = document.getElementById('mst');
const pstEl = document.getElementById('pst');
const timeZones = ['America/New_York', 'America/Chicago', 'America/Denver', 'America/Los_Angeles'];
const getTimes = () => {
const time = new Date();
const timeObj = {
localTime: time.toLocaleString('en-US'),
estTime: time.toLocaleString('en-US', {
timeZone: timeZones[0]
}),
cstTime: time.toLocaleString('en-US', {
timeZone: timeZones[1]
}),
mstTime: time.toLocaleString('en-US', {
timeZone: timeZones[2]
}),
pstTime: time.toLocaleString('en-US', {
timeZone: timeZones[3]
})
}
writeThings(timeObj);
};
const writeThings = obj => {
localEl.innerHTML = obj.localTime;
estEl.innerHTML = obj.estTime;
cstEl.innerHTML = obj.cstTime;
mstEl.innerHTML = obj.mstTime;
pstEl.innerHTML = obj.pstTime;
};
getTimes();