Computing.Net > Forums > Web Development > Add minutes to this javascript!

Add minutes to this javascript!

Reply to Message Icon

Original Message
Name: Stephen Allden
Date: October 16, 2005 at 16:51:34 Pacific
Subject: Add minutes to this javascript!
OS: Windows 98
CPU/Ram: 533Mhz, 191.0MB
Comment:

Click here to see the javascript!

Hiya does anyone know to change this javascript to allow minutes as well as hours. It's a javascript which allows different images to display at different times of the day.

Cheers!!!


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: October 16, 2005 at 18:48:27 Pacific
Reply: (edit)

Changes are in bold.

I wrote it so that the hours are converted to minutes as well so that you don't have to compare two variables in the comparisons (so 90 would be 1:30am). Add as many if..else statements as you need. Note there are 1440 minutes in a day.

day=new Date() //..get the date

h = day.getHours()*60; //get the hour
m = day.getMinutes(); //get the minutes
time = h + m; //total minutes

if(time<90) { // 1:30AM

document.write('<body background="put your first image file name here such as 1.jpg">')

} else if(time<540) { //9:00 am

document.write('<body background="put your second image file name here such as 2.jpg">')

} else if(time<930) { // 3:30 pm

document.write('<body background="put your third image file name here such as 3.jpg">')

} else {

document.write('<body background="put your last image file name here such as 4.jpg">')

}


Report Offensive Follow Up For Removal

Response Number 2
Name: Stephen Allden
Date: October 17, 2005 at 06:37:55 Pacific
Reply: (edit)

Thanks for that mate, just another thing how would i set it to utc hours!


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: October 17, 2005 at 08:39:34 Pacific
Reply: (edit)

I don't know that you can do that automatically. The script is client-side, so it is generating the time based upon the user's computer. Unless you know what time zone the user is in, you can't adjust for UTC.

Michael J


Report Offensive Follow Up For Removal

Response Number 4
Name: tonypig
Date: November 1, 2005 at 05:57:02 Pacific
Reply: (edit)

this site might be useful to you as a reference:

http://www.w3schools.com/jsref/jsref_obj_date.asp


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Add minutes to this javascript!

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge