帮助显示时间 [英] Help Displaying Time

查看:79
本文介绍了帮助显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在特定时区(美国中部)显示时间,无论计算机所在的位置是什么。我写了下面的脚本

显示了美国东部,中部,山区,太平洋和阿拉斯加时间区域的时间

区域。如果计算机位于中央

时区,但如果它位于其他地方,则无效。我知道如何获得UTC时间

和timezoneOffset但是我不知道如何从那里到

中央时间。任何人都可以提供任何建议吗?


< SCRIPT LANGUAGE =" JavaScript">


var running = false

var timerID = null

var dayName = new Array(7)

dayName [0] =" Sun"

dayName [ 1] ="周一>

dayName [2] =" Tue"

dayName [3] =" Wed"

dayName [4] =" Thu"

dayName [5] =" Fri"

dayName [6] =" Sat"


函数countDown(){

var now = new Date()

Present = now.getTime()


running = true

var theDay = now.getDay()

var theDisplayDay = dayName [theDay]

var theHour = now.getHours( )

var theDisplayHour = theHour

var theMin = now.getMinutes()

var theSec = now.getSeconds()

document.forms [0] .displayday.value = theDisplayDay

document.forms [0] .displayhour.value = theDisplayHour + 1

document.forms [0 ] .disp laymin.value = theMin

document.forms [0] .displaysec.value = theSec

document.forms [1] .displayday.value = theDisplayDay

document.forms [1] .displayhour.value = theDisplayHour

document.forms [1] .displaymin.value = theMin

document.forms [1]。 displaysec.value = theSec

document.forms [2] .displayday.value = theDisplayDay

document.forms [2] .displayhour.value = theDisplayHour-1

document.forms [2] .displaymin.value = theMin

document.forms [2] .displaysec.value = theSec

document.forms [3 ] .displayday.value = theDisplayDay

document.forms [3] .displayhour.value = theDisplayHour-2

document.forms [3] .displaymin.value = theMin

document.forms [3] .displaysec.value = the

document.forms [4] .displayday.value = theDisplayDay

document.forms [4] .displayhour.value = theDisplayHour-3

document.forms [4] .displaymin.value = theMin

document.forms [4] .displaysec.value = theSec

if(running){

timerID = setTimeout(" countDown()",1000)

}

}

函数stopTimer(){

clearTimeout(timerID)

running = false

}


< / SCRIPT>

I want to display the time in a particular timezone (US Central) regardless
where the computer is located. I have written the script below which
displays the time in the Eastern, Central, Mountain, Pacific and Alaska time
zones in the US. It works okay if the computer is located in the Central
timezone but not if it is located elsewhere. I know how to get the UTC time
and the timezoneOffset but I can''t figure out how to get from there to
Central time. Can anyone offer any suggestions?

<SCRIPT LANGUAGE="JavaScript">

var running = false
var timerID= null
var dayName=new Array(7)
dayName[0]="Sun"
dayName[1]="Mon"
dayName[2]="Tue"
dayName[3]="Wed"
dayName[4]="Thu"
dayName[5]="Fri"
dayName[6]="Sat"

function countDown() {
var now=new Date()
Present=now.getTime()

running = true
var theDay=now.getDay()
var theDisplayDay = dayName[theDay]
var theHour=now.getHours()
var theDisplayHour=theHour
var theMin=now.getMinutes()
var theSec=now.getSeconds()
document.forms[0].displayday.value= theDisplayDay
document.forms[0].displayhour.value= theDisplayHour+1
document.forms[0].displaymin.value= theMin
document.forms[0].displaysec.value= theSec
document.forms[1].displayday.value= theDisplayDay
document.forms[1].displayhour.value= theDisplayHour
document.forms[1].displaymin.value= theMin
document.forms[1].displaysec.value= theSec
document.forms[2].displayday.value= theDisplayDay
document.forms[2].displayhour.value= theDisplayHour-1
document.forms[2].displaymin.value= theMin
document.forms[2].displaysec.value= theSec
document.forms[3].displayday.value= theDisplayDay
document.forms[3].displayhour.value= theDisplayHour-2
document.forms[3].displaymin.value= theMin
document.forms[3].displaysec.value= theSec
document.forms[4].displayday.value= theDisplayDay
document.forms[4].displayhour.value= theDisplayHour-3
document.forms[4].displaymin.value= theMin
document.forms[4].displaysec.value= theSec
if (running) {
timerID=setTimeout("countDown()",1000)
}
}
function stopTimer() {
clearTimeout(timerID)
running=false
}

</SCRIPT>

推荐答案

我认为日期中有一个函数setTimeZoneOffset()

的对象允许你设置GMT的小时偏差(一般平均时间即格林威治

英格兰)

I think there is a function setTimeZoneOffset() of the Date object that
lets you set hours of offset from GMT (general mean time i.e. greenwich
england)


Melvin G. Sheppers写道:
Melvin G. Sheppers wrote:
我想在特定时区(美国中部)显示时间,无论计算机位于何处。我写了下面的脚本,它显示了美国东部,中部,山区,太平洋和阿拉斯加时区的时间。如果计算机位于中央时区,它可以正常工作,但如果计算机位于其他地方则不行。我知道如何获得UTC时间
和timezoneOffset但我无法弄清楚如何从那里到中央时间。任何人都可以提供任何建议吗?


如果您知道TimezoneOffset,并且您知道CT是-6GMT(忽略

DST),并且某些位置' '偏移包括一小时的分数

(这将影响小时和分钟),你可以计算CT。


now = new Date();

now.setHours(now.getHours()+(now.getTimezoneOffset()/ 60)-6);


Mick


< SCRIPT LANGUAGE =" JavaScript">


var timerID = null
var dayName = new Array(7)
dayName [0] =" Sun"
dayName [1] =" Mon"
dayName [2] =" Tue"
dayName [3] =" Wed"
dayName [4] =" Thu"
dayName [5] =" Fri"
dayName [6] =" Sat"

function countDown( ){
var now = new Date()
Present = now.getTime()

running = true
var theDay = now.getDay()
var theDisplayDay = dayName [theDay]
var theHour = now。 getHours()
var theDisplayHour = theHour
var theMin = now.getMinutes()
var theSec = now.getSeconds()
document.forms [0] .displayday.value = theDisplayDay
document.forms [0] .displayhour.value = theDisplayHour + 1
document.forms [0] .displaymin.value = theMin
document.forms [0] .displaysec.value = theSec
document.forms [1] .displayday.value = theDisplayDay
document.forms [1] .displayhour.value = theDisplayHour
document.forms [1] .displaymin.value = theMin
document.forms [1] .displaysec.value = theSec
document.forms [2] .displayday.value = theDisplayDay
document.forms [2] .displayhour.value = theDisplayHour-1
document.forms [2] .displaymin.value = theMin
document.forms [2] .displaysec.value = theSec
document.forms [3] .displayday.value = theDisplayDay
document.forms [3] .displayhour.value = theDisplayHour-2
document.forms [3] .displaymin.value = theMin
document.forms [3] .displaysec.value = theSec document.forms [4] .displayday .value = theDisplayDay
document.forms [4] .displayhour.value = theDisplayHour-3
document.forms [4] .displaymin.value = theMin
document.forms [4] .displaysec .value = theSec
if(running){
timerID = setTimeout(" countDown()",1000)
}
}
function stopTimer(){
clearTimeout(timerID)
running = false
}
< / SCRIPT>
I want to display the time in a particular timezone (US Central) regardless
where the computer is located. I have written the script below which
displays the time in the Eastern, Central, Mountain, Pacific and Alaska time
zones in the US. It works okay if the computer is located in the Central
timezone but not if it is located elsewhere. I know how to get the UTC time
and the timezoneOffset but I can''t figure out how to get from there to
Central time. Can anyone offer any suggestions?

If you know the TimezoneOffset, and you know that CT is -6GMT (ignoring
DST), and that some locations'' offsets include fractions of an hour
(this will effect the hrs and mins), you may compute CT.

now=new Date();
now.setHours(now.getHours()+(now.getTimezoneOffset ()/60)-6);

Mick

<SCRIPT LANGUAGE="JavaScript">

var running = false
var timerID= null
var dayName=new Array(7)
dayName[0]="Sun"
dayName[1]="Mon"
dayName[2]="Tue"
dayName[3]="Wed"
dayName[4]="Thu"
dayName[5]="Fri"
dayName[6]="Sat"

function countDown() {
var now=new Date()
Present=now.getTime()

running = true
var theDay=now.getDay()
var theDisplayDay = dayName[theDay]
var theHour=now.getHours()
var theDisplayHour=theHour
var theMin=now.getMinutes()
var theSec=now.getSeconds()
document.forms[0].displayday.value= theDisplayDay
document.forms[0].displayhour.value= theDisplayHour+1
document.forms[0].displaymin.value= theMin
document.forms[0].displaysec.value= theSec
document.forms[1].displayday.value= theDisplayDay
document.forms[1].displayhour.value= theDisplayHour
document.forms[1].displaymin.value= theMin
document.forms[1].displaysec.value= theSec
document.forms[2].displayday.value= theDisplayDay
document.forms[2].displayhour.value= theDisplayHour-1
document.forms[2].displaymin.value= theMin
document.forms[2].displaysec.value= theSec
document.forms[3].displayday.value= theDisplayDay
document.forms[3].displayhour.value= theDisplayHour-2
document.forms[3].displaymin.value= theMin
document.forms[3].displaysec.value= theSec
document.forms[4].displayday.value= theDisplayDay
document.forms[4].displayhour.value= theDisplayHour-3
document.forms[4].displaymin.value= theMin
document.forms[4].displaysec.value= theSec
if (running) {
timerID=setTimeout("countDown()",1000)
}
}
function stopTimer() {
clearTimeout(timerID)
running=false
}

</SCRIPT>


< br>

他们如何拥有一小时的分数?我上次检查时区是坚实的时间。

How do they have fractions of an hour? Timezones are solid hour by
hour last time I checked.


这篇关于帮助显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆