1.kod
function clockFormat(val) {
val = val.toString();
return val.length === 1 ? '0' + val : val;
}
function calculateClock(location) {
var timezone = new Date(new Date().toLocaleString('en-US', { timeZone: location }));
var h = timezone.getHours();
var m = timezone.getMinutes();
var s = timezone.getSeconds();
h = clockFormat(h);
m = clockFormat(m);
s = clockFormat(s);
return [ h, m, s ].join(':');
//return [ h, m ].join(':');
}
function generateClock(location, thatElement, isSelf) {
if(typeof thatElement === typeof undefined) {
thatElement = document.getElementsByTagName('body')[0];
isSelf = false;
} else {
if(typeof isSelf === typeof undefined) { isSelf = false; }
}
var data = calculateClock(location);
var elem;
if(isSelf === false) {
elem = document.createElement('span');
thatElement.appendChild(elem);
} else {
elem = thatElement;
}
elem.innerText = data;
setInterval(function() {
elem.innerText = calculateClock(location);
}, 1000);
}
if(!zn) {var zn = 'America/New_York';}
var locations = [
''+zn+'','America/New_York','Europe/Paris','America/Argentina/Buenos_Aires','Asia/Dubai','Asia/Bangkok','America/Lima',
];
var parent = document.getElementById('clocks');
for(var i = 0; i < locations.length; i++) {
generateClock(locations[i], parent);
}
for(var i = 0; i < locations.length; i++) {
generateClock(locations[i], document.getElementById(locations[i]), true);
}2.kod function myClock(){setTimeout(function() {
const d = new Date();const n = d.toLocaleTimeString();
document.getElementById("wsaat").innerHTML = n;
myClock();}, 1000)}myClock();