不带PHP的不同时区时钟?

时间:2014-12-18 08:27:45

标签: javascript

我正在尝试在我的页面上制作两个不同的时钟,一个只跟随DK时间作为标准,一个跟随用户的当地时间。然后我想,如果没有PHP,我可以这样做吗?到目前为止,我无法找到任何可以锁定DK手表时区的东西,而不会在用户计算机上的时间发生变化时更改它。 JS中是否有可以执行此操作的功能,还是需要PHP?

<div class="box">
  <div class="clock">
    <span class="hours"></span>
    <span class="minutes"></span>
    <span class="seconds"></span>
  </div>
  <div class="date">
    <div id="daymonth"></div>
    <div id="year"></div>
  </div>
</div>
<div class="box">
  <div class="clock">
    <span class="offset"></span>
    <span class="minutes"></span>
    <span class="seconds"></span>
  </div>
  <div class="date">
    <div id="daymonth2"></div>
    <div id="year2"></div>
  </div>
</div>
<script>
  var date = new Date(),
  offset = date.getTimezoneOffset()/60,
  year = date.getFullYear(),
  month = date.getMonth(),
  day = date.getUTCDate(),
  months = ["Januar", "Febuar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "October", "November", "December"];

  function pad(number, length) {
    var str = "" + number
    while (str.length < length) {
      str = '0' + str
    }
    return str
  }
  document.getElementById('daymonth').innerHTML = months[month] + " " + day;
  document.getElementById('year').innerHTML = year;
  document.getElementById('daymonth2').innerHTML = months[month] + " " + day;
  document.getElementById('year2').innerHTML = year;
  var clockH = $(".hours");
  var clockM = $(".minutes");
  var clockS = $(".seconds");
  var clockO = $(".offset");

  function time() {
    var d = new Date(),
    s = d.getSeconds() * 6,
    m = d.getMinutes() * 6 + (s / 60),
    h = d.getHours() % 12 / 12 * 365 + (m / 12);
    clockH.css("transform", "rotate(" + h + "deg)");
    clockM.css("transform", "rotate(" + m + "deg)");
    clockS.css("transform", "rotate(" + s + "deg)");
  }

  function timezone() {
    var t = new Date(),
    s = t.getSeconds() * 6,
    m = t.getMinutes() * 6 + (s / 60),
    o = t.getHours() % 12 / 12 * 365 + offset + (m / 12)-60;
    clockO.css("transform", "rotate(" + o + "deg)");
    clockM.css("transform", "rotate(" + m + "deg)");
    clockS.css("transform", "rotate(" + s + "deg)");
  }

  var clock = setInterval(time, 1000);
  time();
  var clock = setInterval(timezone, 1000);
  timezone();
</script>

http://jsfiddle.net/s8qgx0Lx/

0 个答案:

没有答案