...

View Full Version : Countdown Script - Need Help



simpgr9000
01-01-2007, 06:12 AM
Hello,

I would like to know how to Modify.. This script to not show days

Like, instend of 2 days, 10 hrs. ect...

to show up as

58 hrs, 30 mins 30 sec.. ect

Can anyone help me


<span id="tzcd"></span>


<!--Copy and paste just above the close </BODY> of you HTML webpage.-->

<SCRIPT type="text/javascript">

// **** Time Zone Count Down Javascript **** //
/*
Visit http://rainbow.arch.scriptmania.com/scripts/
for this script and many more
*/

////////// CONFIGURE THE COUNTDOWN SCRIPT HERE //////////////////

var month = '*'; // '*' for next month, '0' for this month or 1 through 12 for the month
var day = '1'; // Offset for day of month day or + day
var hour = 0; // 0 through 23 for the hours of the day
var tz = -5; // Offset for your timezone in hours from UTC
var lab = 'tzcd'; // The id of the page entry where the timezone countdown is to show

function start() {displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);}

// ** The start function can be changed if required **
window.onload = start;

////////// DO NOT EDIT PAST THIS LINE //////////////////

function setTZCountDown(month,day,hour,tz)
{
var toDate = new Date();
if (month == '*')toDate.setMonth(toDate.getMonth() + 1);
else if (month > 0)
{
if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);
toDate.setMonth(month-1);
}
if (day.substr(0,1) == '+')
{var day1 = parseInt(day.substr(1));
toDate.setDate(toDate.getDate()+day1);
}
else{toDate.setDate(day);
}
toDate.setHours(hour);
toDate.setMinutes(0-(tz*60));
toDate.setSeconds(0);
var fromDate = new Date();
fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
var diffDate = new Date(0);
diffDate.setMilliseconds(toDate - fromDate);
return Math.floor(diffDate.valueOf()/1000);
}
function displayTZCountDown(countdown,tzcd)
{
if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late.";
else {var secs = countdown % 60;
if (secs < 10) secs = '0'+secs;
var countdown1 = (countdown - secs) / 60;
var mins = countdown1 % 60;
if (mins < 10) mins = '0'+mins;
countdown1 = (countdown1 - mins) / 60;
var hours = countdown1 % 24;
var days = (countdown1 - hours) / 24;
document.getElementById(tzcd).innerHTML = days + " day" + (days == 1 ? '' : 's') + ' ' +hours+ 'h : ' +mins+ 'm : '+secs+'s';
setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
}
}
</SCRIPT>

david_kw
01-01-2007, 06:20 AM
Try changing the three lines near the bottom to this.



var hours = countdown1; // % 24;
// var days = (countdown1 - hours) / 24;
document.getElementById(tzcd).innerHTML = /* days + " day" + (days == 1 ? '' : 's') + ' ' + */ hours+ 'h : ' +mins+ 'm : '+secs+'s';


Ironically I can't test it because it doesn't seem to work when I point it to tomorrow. Either it has trouble going across monthly boundaries or yearly ones or I'm using it incorrectly. I think it should work though.

david_kw

david_kw
01-01-2007, 06:26 AM
Hmm for some reason Edit isn't working. Anyway, I wanted to let you know it seems to work in IE7 across the year boundary. It was FF1.5 where it didn't work for me.

david_kw

david_kw
01-01-2007, 06:34 AM
The problem appears to be

toDate.getYear()

which returns different things depending on the browser. See this link for more info.

http://www.quirksmode.org/js/datecompat.html

So if this is a problem you can probably change it to

toDate.getFullYear()

instead. That would change this line in your code.



if (month <= toDate.getMonth())toDate.setYear(toDate.getFullYear() + 1);


Which makes it work in FF1.5 as well.

david_kw

simpgr9000
01-01-2007, 07:41 AM
So what is the code Now...

can you edit it.. as i'm hopeless in Javascipts

david_kw
01-01-2007, 07:56 AM
Heh, ok I guess. I hope you can at least look at the differences between the scripts so you can learn something. I think of this forum as a place to ask questions so you can learn instead of somewhere to go to ask people to do work for you.



<span id="tzcd"></span>


<!--Copy and paste just above the close </BODY> of you HTML webpage.-->

<SCRIPT type="text/javascript">

// **** Time Zone Count Down Javascript **** //
/*
Visit http://rainbow.arch.scriptmania.com/scripts/
for this script and many more
*/

////////// CONFIGURE THE COUNTDOWN SCRIPT HERE //////////////////

var month = '*'; // '*' for next month, '0' for this month or 1 through 12 for the month
var day = '11'; // Offset for day of month day or + day
var hour = 12; // 0 through 23 for the hours of the day
var tz = -5; // Offset for your timezone in hours from UTC
var lab = 'tzcd'; // The id of the page entry where the timezone countdown is to show

function start() {displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);}

// ** The start function can be changed if required **
window.onload = start;

////////// DO NOT EDIT PAST THIS LINE //////////////////

function setTZCountDown(month,day,hour,tz)
{
var toDate = new Date();
if (month == '*')toDate.setMonth(toDate.getMonth() + 1);
else if (month > 0)
{
if (month <= toDate.getMonth())toDate.setYear(toDate.getFullYear() + 1);
toDate.setMonth(month-1);
}
if (day.substr(0,1) == '+')
{var day1 = parseInt(day.substr(1));
toDate.setDate(toDate.getDate()+day1);
}
else{toDate.setDate(day);
}
toDate.setHours(hour);
toDate.setMinutes(0-(tz*60));
toDate.setSeconds(0);
var fromDate = new Date();
fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
var diffDate = new Date(0);
diffDate.setMilliseconds(toDate - fromDate);
return Math.floor(diffDate.valueOf()/1000);
}
function displayTZCountDown(countdown,tzcd)
{
if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late.";
else {var secs = countdown % 60;
if (secs < 10) secs = '0'+secs;
var countdown1 = (countdown - secs) / 60;
var mins = countdown1 % 60;
if (mins < 10) mins = '0'+mins;
countdown1 = (countdown1 - mins) / 60;
var hours = countdown1; // % 24;
// var days = (countdown1 - hours) / 24;
document.getElementById(tzcd).innerHTML = /* days + " day" + (days == 1 ? '' : 's') + ' ' + */ hours+ 'h : ' +mins+ 'm : '+secs+'s';
setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
}
}
</SCRIPT>


david_kw

simpgr9000
01-01-2007, 08:01 AM
Thanks, for the help..

As for me being able to code myself.. i would really like to learn, but the person teaching me would have to have Lots of space time..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum