Heim >Web-Frontend >js-Tutorial >根据地区不同显示时间的javascript代码_javascript技巧

根据地区不同显示时间的javascript代码_javascript技巧

WBOY
WBOYOriginal
2016-05-16 19:10:441310Durchsuche

by tingting 

<script> <BR><!-- Begin <BR>var timerRunning = false; <BR>var timezone = "格林尼治标准时间"; <BR>var adjust = 0; <br><br>function timeCheck(tzone, diff) { <BR>if (timerRunning) { <BR>clearTimeout(updatetime); <BR>timerRunning = false; } <BR>gmtOffset=eval(diff+adjust); <BR>timezone = tzone; <BR>checkDateTime(); <BR>} <br><br>function checkDateTime () { <BR>var today = new Date(); <BR>var year = today.getYear() + 00; <BR>var month = today.getMonth()+1; <BR>var date = today.getDate(); <BR>var day = today.getDay(); <BR>var hour = today.getHours(); <BR>var minute = today.getMinutes(); <BR>var second = today.getSeconds(); <br><br>var lastSat = date - (day+1); <BR>while (lastSat < 32) lastSat+=7; <BR>if (lastSat > 31) lastSat+=-7; <BR>var firstSat = date - (day+1); <BR>while (firstSat > 0) firstSat+=-7; <BR>if (firstSat < 1) firstSat+=7; <BR>if ((((month == 4) && (date >= firstSat)) || month > 4) && <BR>(month < 11 || ((month == 10) && day <= lastSat))) adjust += 60; <BR>yourOffset = (new Date()).getTimezoneOffset(); <BR>yourOffset = yourOffset + adjust; <br><br>var xx = navigator.appName <BR>var xy = navigator.appVersion; <BR>xy = xy.substring(0,1); <BR>if ((xy == 4) && (xx == "Netscape")) yourOffset = yourOffset+adjust; <BR>if ((((month == 4) && (date > 20)) || month > 4) && (month < 11 || ((month == 10) && <BR>day < 30))) adjust -= 60; <br><br>ourDifference = eval(gmtOffset - yourOffset); <BR>var half = eval(ourDifference % 60); <BR>ourDifference = Math.round(ourDifference / 60); <BR>hour = eval(hour - ourDifference); <BR>var m = new Array("", <BR>"1","2","3", <BR>"4","5","6", <BR>"7","8","9", <BR>"10","11","12"); <BR>var leap = eval(year % 4); <br><br>if ((half == -30) || (half == 30)) minute += 30; <BR>if (minute > 59) minute -= 60, hour++; <BR>if (minute < 0) minute += 60, hour--; <BR>if (hour > 23) hour -= 24, date += 1; <BR>if (((month == 4) || (month == 6) || <BR>(month == 9) || (month == 11)) && (date==31)) date = 1, month ++; <BR>if (((month == 2) && (date > 28)) && (leap != 0)) date = 1, month ++; <BR>if ((month == 2) && (date > 29)) date = 1, month++; <BR>if (hour < 0) hour += 24, date --; <BR>if ((date == 32) && (month == 12)) month = m[1], date = 1, year++; <BR>if (date == 32) date = 1, month++; <BR>if ((date < 1) && (month == 1)) month= m[12], date = 31, year--; <BR>if (date < 1) date = 31, month --; <BR>if (((month == 4) || (month == 6) || <BR>(month== 9) || (month == 11)) && (date == 31)) date = 30; <BR>if ((month == 2) && (date > 28)) date = 29; <BR>if (((month == 2) && (date > 28)) && (leap != 0)) date=28; <BR>for (i=1; i<13; i++) { <BR>if (month == i) { <BR>month = m; break; <BR> } <BR>} <br><br>var dateTime = hour; <BR>dateTime = ((dateTime < 10) ? "0":"") + dateTime; <BR>dateTime = " " + dateTime; <BR>dateTime += ((minute < 10) ? ":0" : ":") + minute; <BR>dateTime += ((second < 10) ? ":0" : ":") + second; <BR>dateTime += (hour >= 12) ? "下午, " : "上午, "; <BR>dateTime += year + "年" + month + "月" + date + "日" ; <br><br>document.clock.zonetime.value = dateTime; <BR>document.clock.zonename.value = timezone; <BR>updatetime=setTimeout("checkDateTime()", 900); <BR>timerRunning = true; <BR>} <BR>// End --> <BR></script>



当前的时间 
     

当前的地区 






Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn