時間の操作(JavaScript版)については、エリア別に対応時間を表示します.
7596 ワード
今はプロジェクトがほぼ一段落しました.せっかくの暇があります.今日は数時間で機能モジュールを完成しました.各エリアによって対応時間が表示されます.この方面ではオンラインでは基本的に既成のサンプルがありません.コードを下記のように貼り付けます.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title> </title>
<script type="text/javascript">
<!-- Begin
function changeTZ() {
var selectedValue = document.getElementById("TZ").value;
var timeZone = selectedValue.split("*")[0];
var city = selectedValue.split("*")[1];
//console.log(" :" + city + "、 :" + timeZone);
var date = new Date();
var currentTimezone = -(date.getTimezoneOffset()/60);//
var timeDifference = currentTimezone - timeZone;//
console.log(" :"+currentTimezone+"、 :"+timeDifference);
var year = 0; // :
var month = 0; // :
var day = 0; // :
var hour = 0; // :
var minute = 0;// :
var second = 0;// :
var currentYear = date.getFullYear(); // :
var currentMonth = date.getMonth()+1; // :
var currentDay = date.getDate(); // :
var currentHour = date.getHours(); // :
var currentMinute = date.getMinutes();// :
var currentSecond = date.getSeconds();// :
second = currentSecond;
if(timeDifference.toString().split(".").length == 2){//
var intVlaue = parseInt(timeDifference.toString().split(".")[0]);//
var floatVlaue = timeDifference - intVlaue;//
hour = currentHour- intVlaue;
minute = currentMinute - floatVlaue*60;
if(minute>=60){
hour = hour + 1;
minute = minute - 60;
}else if(minute < 0){
hour = hour - 1;
minute = 60 + minute;
}
//console.log(" ( ):" + currentHour+"、 ( ):"+hour);
}else{
hour = currentHour-timeDifference;
minute = currentMinute;
}
if(hour >= 24){
day = currentDay + 1;
hour = hour - 24;
}else if(hour >= 0 && hour < 24){
day = currentDay;
hour = hour;
}else if(hour < 0){
day = currentDay - 1;
hour = hour + 24;
}
if(currentMonth==1 || currentMonth==3 || currentMonth==5 || currentMonth==7 || currentMonth==8 || currentMonth==10 || currentMonth==12 ){//31
if(day > 31){
if(currentMonth==12){
year = currentYear + 1;
month= 1;
day = day - 31;
}else{
year = currentYear;
month= currentMonth + 1;
day = day - 31;
}
}else if(day == 0){
if(currentMonth==1){
year = currentYear - 1;
month= 12;
day = 31;
}else{
year = currentYear;
month= currentMonth - 1;
if(month==4 || month==6 || month==9 || month==11){
day = 30;
}else if(month==2){
if((year % 400 == 0)||(year % 4 == 0)&&(year % 100 != 0)){//
day = 29;
}else{//
day = 28;
}
}
}
}else{
year = currentYear;
month= currentMonth;
day = day;
}
}
if(currentMonth==4 || currentMonth==6 || currentMonth==9 || currentMonth==11){//30
if(day > 30){
year = currentYear;
month= currentMonth + 1;
day = day - 30;
}else if(day == 0){
year = currentYear;
month= currentMonth - 1;
day = 31;
}else{
year = currentYear;
month= currentMonth;
day = day;
}
}
if(currentMonth==2){//28 29
year = currentYear;
if((year % 400 == 0)||(year % 4 == 0)&&(year % 100 != 0)){//
if(day > 29){
year = currentYear;
month= currentMonth + 1;
day = day - 29;
}else if(day == 0){
year = currentYear;
month= 1;
day = 31;
}else{
year = currentYear;
month= currentMonth;
day = day;
}
}else{//
if(day > 28){
year = currentYear;
month= currentMonth + 1;
day = day - 28;
}else if(day == 0){
year = currentYear;
month= 1;
day = 31;
}else{
year = currentYear;
month= currentMonth;
day = day;
}
}
}
hour = ((hour <= 9) ? ("0" + hour) : hour);
minute = ((minute <= 9) ? ("0" + minute) : minute);
second = ((second <= 9) ? ("0" + second) : second);
Clock.innerHTML = city + ":" + year +" "+ month +" "+ day +" " + hour + ":" + minute + ":" + second;
setTimeout("changeTZ()", 1000);
}
// End -->
</script>
</head>
<body bgcolor="#ffffff" onLoad="javascript:changeTZ();">
<div id="Clock"></div>
<select style="font-size: 9pt;" onchange="changeTZ()" id="TZ">
<option value="-12* ">GMT-12</option>
<option value="-11* ">GMT-11</option>
<option value="-10* ">GMT-10</option>
<option value="-9* ">GMT-9</option>
<option value="-8* ">GMT-8</option>
<option value="-7* ">GMT-7</option>
<option value="-6* ">GMT-6</option>
<option value="-5* ">GMT-5</option>
<option value="-4.5* ">GMT-4.5</option>
<option value="-4* ">GMT-4</option>
<option value="-3.5* ">GMT-3.5</option>
<option value="-3* ">GMT-3</option>
<option value="-2* ">GMT-2</option>
<option value="-1* ">GMT-1</option>
<option value="0* ">GMT</option>
<option value="1* ">GMT +1</option>
<option value="2* ">GMT +2</option>
<option value="3* ">GMT +3</option>
<option value="3.5* ">GMT+3.5</option>
<option value="4* ">GMT +4</option>
<option value="4.5* ">GMT+4.5</option>
<option value="5* ">GMT +5</option>
<option value="5.5* ">GMT+5.5</option>
<option value="5.75* ">GMT+5.75</option>
<option value="6* ">GMT +6</option>
<option value="6.5* ">GMT+6.5</option>
<option value="7* ">GMT +7</option>
<option value="8* " selected>GMT +8</option>
<option value="9* ">GMT +9</option>
<option value="9.5* ">GMT+9.5</option>
<option value="10* ">GMT +10</option>
<option value="11* ">GMT +11</option>
<option value="12* ">GMT +12</option>
</select>
</body>
</html>
【0分ダウンロードコード】