Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


JavaScript: Date()

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Web Development
View previous topic :: View next topic  
Author Message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 697

PostPosted: Sun Oct 03, 2010 1:04 pm    Post subject: JavaScript: Date() Reply with quote

I have no idea why it won't work.

Here is the HTML file:

Code:
<html>

<head>
<script src="./DateTime.js" type="text/javascript"></script>
</head>

<body onLoad="fnUpdate()">
<form name="form">
<textarea cols="50" name="clock" rows="5">Loading...</textarea>
</form>
</body>

</html>


Here is the JavaScript:
Code:
function fnTimeZone(amTimeZone, amOffSet, amDaylightSavings)
{
   this.DateTime = new Date();
   this.TimeZone = amTimeZone;
   this.OffSet = amOffSet;
   this.DaylightSavings = amDaylightSavings;
}

function fnClockString(amDateTime)
{
   var sgBuffer, dtAMPM;

   var dtYear = amDateTime.getUTCFullYear();
   var dtMonth = amDateTime.getUTCMonth() + 1;
   var dtDay = amDateTime.getUTCDate();
   var dtHour = amDateTime.getUTCHours();
   var dtMinute = amDateTime.getUTCMinutes();
   var dtSecond = amDateTime.getUTCSeconds();

   dtYear = dtYear.toString();

   if(0 <= dtHour && dtHour < 12)
   {
      dtAMPM = "AM";
   } else {
      dtAMPM = "PM";
      dtHour -= 12;
      if(dtHour === 0)
      {
         dtHour = 12;
      }
   }

   if(dtMinute < 10)
   {
      dtMinute = "0" + dtMinute;
   }

   if(dtSecond < 10)
   {
      dtSecond = "0" + dtMinute;
   }

   sgBuffer = dtMonth + '/' + dtDay + '/' + dtYear; // dtYear or dtYear.substr(2, 2)
   sgBuffer = sgBuffer + ' ' + dtHour + ':' + dtMinute + ':' + dtSecond + ' ' + dtAMPM;

   return sgBuffer;
}

function fnUpdate()
{
   // Time zones
   var ayDateTimes = new Array
   (
      new fnTimeZone("SFO: ", -8, 1), new fnTimeZone("NYC: ", -5, 1)
   );

   var otDateTime = new Date();

   // Handle daylight savings
   var otStartDaylightSavings = new Date(otDateTime.getFullYear(), 3, 1);
   while(otStartDaylightSavings.getDay() !== 0)
   {
      otStartDaylightSavings.setDate(otStartDaylightSavings.getDate() + 1);
   }

   var otEndDaylightSavings = new Date(otDateTime.getFullYear(), 9, 31);
   while(otEndDaylightSavings.getDay !== 0)
   {
      otEndDaylightSavings.getDate(otEndDaylightSavings.getDate() - 1);
   }

   var bDaylightSavings;
   if(otStartDaylightSavings < otDateTime && otDateTime < otEndDaylightSavings)
   {
      bDaylightSavings = 1; // True
   } else {
      bDaylightSavings = 0; // False
   }

   for(var nDateTimes = 0; nDateTimes < ayDateTimes.length; nDateTimes++)
   {
      if(ayDateTimes[nDateTimes].DaylightSavings == 1 && bDaylightSavings == 1)
      {
         ayDateTimes[nDateTimes].OffSet++;
      }
   }

   // Get GMT time then apply offsets
   var otGMT = new Date();

   for(nDateTimes = 0; nDateTimes < ayDateTimes.length; nDateTimes++)
   {
      ayDateTimes[nDateTimes].DateTime = new Date(otGMT.getTime() + otGMT[nDateTimes].OffSet * 3600 * 1000);
   }

   window.document.form.clock.value = ayDateTimes[0].TimeZone + fnClockString(ayDateTimes[0].DateTime);
}
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Sun Oct 03, 2010 5:45 pm    Post subject: Reply with quote

It crashes Firefox every time. Try posting it in Programming Section. This looks like a job for Wiccan.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Web Development All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites