如何设置GMT(S)伊朗的时钟?

时间:2011-08-11 23:11:45

标签: javascript jquery

GMT iran-tehran +3:30,但为什么这个网站:http://wwp.greenwichmeantime.com/time-zone/asia/iran/tehran/为伊朗德黑兰+4:30提供GMT。

如何在伊朗改变GMT时设置自己的时钟(在我的代码中)? 我的代码: http://jsfiddle.net/HZmPg/1/

var int=self.setInterval("clock()",1000);
            function clock()
            {
            var d=calcTime('+3')
            var t=d.toLocaleTimeString();
            document.getElementById("clock").innerHTML=t;
            }
    function calcTime(offset) {

    // create Date object for current location
    d = new Date();

    // convert to msec
    // add local time zone offset 
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));

    // return time as a string
    return nd;

}

尊重

2 个答案:

答案 0 :(得分:1)

应该有效:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Lorem ipsum</title>
  <style>
  </style>
</head>
<body>
<script type="text/javascript">
var interval = self.setInterval("clock()", 1000);
function clock(){
  var date = new Date();
  var hourOffset = 3;
  date.setUTCHours(date.getUTCHours(), date.getUTCMinutes());
  var time = date.getTime();
  date.setUTCFullYear(date.getUTCFullYear(), 2, 22);
  var dstStart = date.getTime();
  date.setUTCFullYear(date.getUTCFullYear(), 8, 22);
  var dstEnd = date.getTime();
  if(time > dstStart && time < dstEnd)hourOffset = 4;
  date.setUTCHours(date.getUTCHours()+hourOffset, date.getUTCMinutes()+30);
  var output = date.getUTCHours()+":"+date.getUTCMinutes()+":"+date.getUTCSeconds();    document.getElementById("clock").innerHTML=output;
}
</script>
<b id="clock"></b>
</body>
</html>

答案 1 :(得分:0)

德黑兰似乎目前正处于夏令时。

$ TZ=Asia/Tehran date ; date -u
Fri Aug 12 03:45:44 IRDT 2011
Thu Aug 11 23:15:44 UTC 2011