ウェブサイトにデジタル時計のようなタイマーを入れたいです。日付と時刻が含まれます。私はそれを行うために次のコードを持っています:
var clockID = 0;
function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
var tDate = new Date();
var in_hours = tDate.getHours()
var in_minutes=tDate.getMinutes();
var in_seconds= tDate.getSeconds();
if(in_minutes < 10)
in_minutes = '0'+in_minutes;
if(in_seconds<10)
in_seconds = '0'+in_seconds;
if(in_hours<10)
in_hours = '0'+in_hours;
document.getElementById('theTime').innerHTML = ""
+ in_hours + ":"
+ in_minutes + ":"
+ in_seconds;
clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
clockID = setTimeout("UpdateClock()", 500);
}
function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}
しかし、このコードは現在のコンピューターの時刻を表示しているため、時刻が私のタイムゾーンに適合していません。タイムゾーンに従って日付と時刻が表示されるように、コードに他に何を追加する必要がありますか?日付がDSTの場合は、DSTの正確な時刻も表示されます。