_javascript tips for JavaScript code with different display times for regions

Source: Internet
Author: User
Tags diff eval
by Tingting

<script language= "JavaScript" >
<!--Begin
var timerrunning = false;
var timezone = "Greenwich Standard Time";
var adjust = 0;

function Timecheck (Tzone, diff) {
if (timerrunning) {
Cleartimeout (UpdateTime);
Timerrunning = false; }
Gmtoffset=eval (Diff+adjust);
TimeZone = Tzone;
Checkdatetime ();
}

function Checkdatetime () {
var today = new Date ();
var year = Today.getyear () + 00;
var month = Today.getmonth () +1;
var date = Today.getdate ();
var day = Today.getday ();
var hour = today.gethours ();
var minute = Today.getminutes ();
var second = Today.getseconds ();

var Lastsat = date-(day+1);
while (Lastsat <) lastsat+=7;
if (Lastsat >) lastsat+=-7;
var Firstsat = date-(day+1);
while (Firstsat > 0) firstsat+=-7;
if (Firstsat < 1) firstsat+=7;
if (((month = 4) && (date >= Firstsat) | | month > 4) &&
(Month < 11 | | ((month =) && Day <= Lastsat)) Adjust + 60;
Youroffset = (new Date ()). getTimezoneOffset ();
Youroffset = Youroffset + adjust;

var xx = Navigator.appname
var xy = navigator.appversion;
XY = xy.substring (0,1);
if (xy = = 4) && (xx = = "Netscape") Youroffset = Youroffset+adjust;
if (((month = 4) && (date >) | | month > 4) && (Month < 11 | | ((month = &&)
Day <)) adjust-= 60;

Ourdifference = eval (gmtoffset-youroffset);
var half = eval (ourdifference% 60);
Ourdifference = Math.Round (OURDIFFERENCE/60);
hour = eval (hour-ourdifference);
var m = new Array ("",
"1", "2", "3",
"4", "5", "6",
"7", "8", "9",
"10", "11", "12");
var leap = eval (year% 4);

if ((half = = 30) | | (half = 30)) Minute + 30;
if (minute >) minute =, hour++;
if (minute < 0) minute +, hour--;
if (hour >) hour = =, date + 1;
if ((month = 4) | | (month = 6) | |
(month = 9) | | (month = 11)) && (date==31) date = 1, month + +;
if ((month = 2) && (Date >) && (Leap!= 0)) Date = 1, month + +;
if ((month = 2) && (date >)) date = 1, month++;
if (hour < 0) hour + =, date--;
if (date = && (month =)) month = m[1], date = 1, year++;
If date = 1, month++;
if (Date < 1) && (month = = 1)) month= m[12], date = n, year--;
if (date < 1) date = month-;
if ((month = 4) | | (month = 6) | |
(month== 9) | | (month = 11)) && date = 30;
if (month = 2) && (date >) date = 29;
if ((month = = 2) && (Date >) && (Leap!= 0)) date=28;
For (I=1 i<13; i++) {
if (month = = i) {
month = m; Break
}
}

var dateTime = hour;
datetime = (DateTime < 10)? "0": "") + DateTime;
datetime = "" + datetime;
DateTime = = ((minute < 10)? ": 0": ":") + minute;
DateTime = = ((second < 10)? ": 0": ":") + second;
DateTime = = (Hour >= 12)? "Afternoon,": "Morning,";
DateTime + + "Year" + Month + "Month" + Date + "Day";

Document.clock.zonetime.value = DateTime;
Document.clock.zonename.value = timezone;
Updatetime=settimeout ("Checkdatetime ()", 900);
Timerrunning = true;
}
End-->
</script>
<body onload= "Timecheck (timezone, 0)" >
<form name=clock>
The current time <input size=28 name=zonetime>
<BR><BR> Current Regional <input size=21 name=zonename> <BR><BR>
<div style= "Background-color: #FF0000; width:100px; height:100px "onmouseover=" Timecheck (' Pacific ', +480) "></div>
<div style= "Background-color: #FF00FF; width:100px; height:100px "onmouseover=" Timecheck (' Hawaii ', +600) "></div>
</FORM>
</body>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.