更改 GMT(时区)有问题吗?
我创建了一个小脚本来显示时间(UTC-+3.5
)。问题在于,伊朗的格林尼治标准时间 (+4.5, +3.5) 每年每六个月更改一次 ,并更改时间来回拉动(夏令时
)
我如何设置自己的时钟并更改伊朗的格林威治标准时间?我该怎么办? (现在伊朗的 GMT 为 +4.5)
示例: 我的code-jsfiddle
var int = self.setInterval("clock()", 1000);
function clock() {
var d = calcTime('+4.5')
var t = d.toLocaleTimeString();
document.getElementById("clock").innerHTML = t;
}
function calcTime(offset) {
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000 * offset));
return nd;
}
尊重
I created a small script to display the time(UTC-+3.5
). The problem is there that changes GMT(+4.5, +3.5) in Iran every six months in year, and changes Time is pulled back and forth (Daylight Saving
)
How i set yourself clock with change GMT in iran? what do i do? (now GMT in iran is +4.5)
EXAMPLE: my code-jsfiddle
var int = self.setInterval("clock()", 1000);
function clock() {
var d = calcTime('+4.5')
var t = d.toLocaleTimeString();
document.getElementById("clock").innerHTML = t;
}
function calcTime(offset) {
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000 * offset));
return nd;
}
With respect
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
小提琴示例
这有效。它将检查当前日期是否超过 9 月 21 日,如果是,则 GMT 的值为 -4.5,否则为 3.5,
这不是我写过的最干净的代码,我只是修改了你的代码。不过你现在可以看到它是如何完成的。
Fiddle Example
This works. It will check if the date is currently past September 21st and if it is it will -4.5 from GMT otherwise 3.5
it is not the cleanest code i've ever written, I just modified yours. however you can see how it is done now.