Clock in different time zones

前端 未结 6 1467
南方客
南方客 2021-01-12 18:08

I am trying to create two clocks on a website that says two times on it. One from London and the other from New York.

I have been able to create a clock that reads t

6条回答
  •  没有蜡笔的小新
    2021-01-12 18:45

    You can add or subtract hours from your date with

    currentTime.setHours(currentTime.getHours()+offset);
    

    where offset is any number of hours.

    I updated the jsfiddle with that line and the function so that it accepts a parameter for the offset. This is not the UTC offset, just how many hours to add from the system time. You can get the current UTC offset by currentTime.getTimezoneOffset()/60

    Demo

提交回复
热议问题