本文介绍了帮助显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想在特定时区(美国中部)显示时间,无论计算机所在的位置是什么。我写了下面的脚本 显示了美国东部,中部,山区,太平洋和阿拉斯加时间区域的时间 区域。如果计算机位于中央 时区,但如果它位于其他地方,则无效。我知道如何获得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) regardlesswhere the computer is located. I have written the script below whichdisplays the time in the Eastern, Central, Mountain, Pacific and Alaska timezones in the US. It works okay if the computer is located in the Centraltimezone but not if it is located elsewhere. I know how to get the UTC timeand the timezoneOffset but I can''t figure out how to get from there toCentral time. Can anyone offer any suggestions? <SCRIPT LANGUAGE="JavaScript"> var running = falsevar timerID= nullvar 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 = truevar theDay=now.getDay()var theDisplayDay = dayName[theDay]var theHour=now.getHours()var theDisplayHour=theHourvar theMin=now.getMinutes()var theSec=now.getSeconds()document.forms[0].displayday.value= theDisplayDaydocument.forms[0].displayhour.value= theDisplayHour+1document.forms[0].displaymin.value= theMindocument.forms[0].displaysec.value= theSecdocument.forms[1].displayday.value= theDisplayDaydocument.forms[1].displayhour.value= theDisplayHourdocument.forms[1].displaymin.value= theMindocument.forms[1].displaysec.value= theSecdocument.forms[2].displayday.value= theDisplayDaydocument.forms[2].displayhour.value= theDisplayHour-1document.forms[2].displaymin.value= theMindocument.forms[2].displaysec.value= theSecdocument.forms[3].displayday.value= theDisplayDaydocument.forms[3].displayhour.value= theDisplayHour-2document.forms[3].displaymin.value= theMindocument.forms[3].displaysec.value= theSecdocument.forms[4].displayday.value= theDisplayDaydocument.forms[4].displayhour.value= theDisplayHour-3document.forms[4].displaymin.value= theMindocument.forms[4].displaysec.value= theSecif (running) {timerID=setTimeout("countDown()",1000)}}function stopTimer() {clearTimeout(timerID)running=false} </SCRIPT>推荐答案 这篇关于帮助显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 09:12