Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2012, 03:09 AM   PM User | #1
Cremator
New Coder

 
Join Date: Jan 2012
Location: in the uk.
Posts: 99
Thanks: 2
Thanked 6 Times in 4 Posts
Cremator has a little shameless behaviour in the past
Countdown timer.

Based on a post in this thread http://www.codingforums.com/showpost...8&postcount=15, the count down timer is made out of elements in the post a script section.

A bit rough and ready, if anyone finds a better route, please post here.
Html:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Untitled Document</title>
<
script>
function 
tween(rfcDateBegin,rfcDateEnd){
    
rfcDateBegin rfcDateBegin || false;
    
rfcDateEnd rfcDateEnd || false;
    if( 
rfcDateBegin && rfcDateEnd ) return new Date(rfcDateEnd).getTime() - new Date(rfcDateBegin).getTime();
return 
null;
}

Date.prototype.getNextDow = function(dow){
        
dow dow || 0;
        
// finds first dow from day in date object in the month set in the date object and likewise the year.
        
for(dayNo=this.getDate(); (this.getDate()+9)>dayNodayNo++){
            
futureDate = new Date(this.getFullYear(), this.getMonth() , dayNo);
            
// we only check forward 9 days, if we don't find anything then we have a problem!
            
if( futureDate.getDay()==dow ) return futureDate.getTime(); // return date value
            
}
return 
false// we return something because we have to!
}

Number.prototype.convertToReference = function(){

    
// reduce to seconds
    
tmp Math.floorthis 1000 );
    
= [];
    
days Math.floor(tmp / ( 60 60 24 )); // number of days
    
if( days>0){ r.push(  days " Days, " ); tmp -= ( days 60 60 24); }
    
    
hours Math.floortmp / ( 60 60 ));
    if( 
hours>0){ r.pushhours " Hrs, " ); tmp -= ( hours 60 60 ); }
    
    
minutes Math.floortmp 60 );
    if( 
minutes>){ r.pushminutes" Mins, "); tmp -= ( minutes 60 ); }
    
    
r.pushtmp " Secs.");
    return 
r.join("");
    
}
function 
update(){
// get the time now.
nowObj = new Date();
now = new Date().getTime();
// get the nearest Friday from 'now
target nowObj.getNextDow(5); // 4 == friday
remaining tweennow target offset );
tg.value remaining.convertToReference ();
}
offset tween("1 Jan 2012 00:00:00","1 Jan 2012 16:00:00"); // ==57600000 ms, this is midnight to 4pm as milliseconds
setIntervalupdate 1000);
</script>
</head>
<body onload="tg=document.getElementById('remain');"><input type="text" id="remain" value="" size="30" />

</body>
</html> 
The example above counts down to 4pm on Friday of the current week.

With some modification your able to create a count timer that auto resets, any event that you want to trigger at zero hour will be up to yourselves to implement.
Cremator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:56 AM.


Advertisement
Log in to turn off these ads.