let repLoc = (typeof Intl == 'object' &&
typeof Intl.DateTimeFormat == 'function' &&
typeof Intl.DateTimeFormat().resolvedOptions == 'function')?
Intl.DateTimeFormat().resolvedOptions().timeZone : 'default';
function setRepLoc(evt) {
showSampleDates(this.value);
}
function showSampleDates(repLoc) {
let el0 = document.getElementById('sDate0');
let el1 = document.getElementById('sOff0');
let el2 = document.getElementById('sDate1');
let el3 = document.getElementById('sOff1');
let d0 = new Date(Date.UTC(2020,0,1,11));
let d1 = new Date(Date.UTC(2020,5,1,11));
let opts = {
weekday: 'short',
day: 'numeric',
month: 'short',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
timeZone: repLoc,
timeZoneName: 'long'
};
let offOpts = {
hour: 'numeric',
hour12: false,
timeZone: repLoc,
timeZoneName: 'short'
}
if (repLoc == 'default') {
el0.textContent = '';
el1.textContent = '';
el2.textContent = '';
el3.textContent = '';
} else {
el0.textContent = d0.toLocaleString('en-NZ', opts);
el1.textContent = d0.toLocaleString('en-NZ', offOpts).split(' ')[1];
el2.textContent = d1.toLocaleString('en-NZ', opts);
el3.textContent = d1.toLocaleString('en-NZ', offOpts).split(' ')[1];
}
}
window.onload = function(){
let sel = document.getElementById('repLoc')
if (repLoc) {
sel.options[0].text = repLoc;
sel.options[0].value = repLoc;
sel.selectedIndex = 0;
setRepLoc.call(sel);
}
sel.addEventListener(
'change',
setRepLoc,
false);
};
td:nth-child(1){text-align:right;color:#999;}
td:nth-child(2){font-family:monospace}
<table>
<tr>
<td>IANA loc:
<td><select id="repLoc">
<option selected value="default">Select a location
<option>Europe/Amsterdam
<option>Europe/Andorra
<option>Europe/Astrakhan
<option>Europe/Athens
<option>Europe/Belfast
<option>Pacific/Samoa
<option>Pacific/Kiritimati
<option>Antarctica/DumontDUrville
<option>Antarctica/Davis
<option>America/Chicago
<option>Australia/Brisbane
</select>
<tr>
<td>Sample:
<td id="sDate0">
<tr>
<td>Offset:
<td id="sOff0">
<tr>
<td>Sample:
<td id="sDate1">
<tr>
<td>Offset:
<td id="sOff1">
</table>