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 -> General programming
View previous topic :: View next topic  
Author Message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Mon Oct 04, 2010 3:20 am    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
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Oct 05, 2010 11:51 pm    Post subject: Reply with quote

Anyone? Sad
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Wed Oct 06, 2010 4:01 am    Post subject: Reply with quote

"It doesn't work," is not very descriptive. Which part doesn't work?
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Wed Oct 06, 2010 8:29 am    Post subject: Reply with quote

justa_dude wrote:
"It doesn't work," is not very descriptive. Which part doesn't work?


It was as descriptive as I can be. The page does not even load up. It stays blanks with the mouse in the loading symbol stage.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Wed Oct 06, 2010 12:59 pm    Post subject: Reply with quote

Try properly formatting your HTML page. As in, including the DocType at the top of the page, adjusting the html and header blocks as needed based on the doctype you use and so on.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Wed Oct 06, 2010 5:04 pm    Post subject: Reply with quote

It's a lot easier to isolate a problem if you start with something that works. You can, however, try to go in reverse by removing things until you get expected output. If you reduce your program to simply writing "Hello, world" in the textarea then the rest will be a lot easier to debug and you will be asking much less of us in terms of trying to study your code.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming 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 can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites