0

I want to display 3 clocks from 3 different time zones using JavaScript. I browsed around the web searching for a simple solution but all I found was long scripts and .js extensions, all those to complete a simple task.

Is there an easy way to do this? do I really have to add an additional JS file to complete this task?

Thanks in advance to the helpers!

4

1 に答える 1

3

これを行う簡単な方法はありますか?

はい。

このタスクを完了するには、本当に追加の JS ファイルを追加する必要がありますか?

いいえ。ただし、JS での時間の処理は困難です。なぜなら、JS にはクロスブラウザセーフな日付/時刻文字列の解析およびフォーマット方法がないからです。そのためにライブラリを使用すると便利ですが、時計には必要ありません。

// all three clocks represent current time
var clock1 = new Date(); // current moment
var clock2 = new Date();
var clock3 = new Date();

// for outputting, adjust them
// leave clock1 in UTC
clock2.setHours(clock2.getHours() + 3); // UTC+3
clock3.setHours(clock3.getHours() - 5); // UTC-5

// now for display, use these values:
clock1.getUTCHours();
clock1.getUTCMinutes();
clock1.getUTCSeconds();

clock2.getUTCHours();
clock2.getUTCMinutes();
clock2.getUTCSeconds();

clock3.getUTCHours();
clock3.getUTCMinutes();
clock3.getUTCSeconds();
于 2013-02-19T20:21:47.180 に答える