PDA

View Full Version : Countdown Timer Help



mclarensquall
10-21-2008, 09:34 AM
Hi guys, I have a problem with my counter. i can get the min, sec and hour to work but not the rest. Really need some help over here. Thanks.



<html>

<script type="text/javascript">

function showtime() {

var endDate = new Date("05/14/2009");
var dateDiff= Math.floor((endDate - new Date()/1000));

var secDiff = (dateDiff/1)%60;
var minDiff = Math.floor((dateDiff/60)%60);
var hourDiff = Math.floor((dateDiff/(60*60))%24);
var dayDiff = Math.floor((dateDiff/(60*60*24))%30);
var weekDiff = Math.floor((dateDiff/(60*60*24*30))%4);
var mthDiff = Math.floor((dateDiff/(60*60*24*7*4))%12);


document.getElementById('display').innerHTML = mthDiff + " mth " + weekDiff + " week " + dayDiff + " day " + hourDiff + " hour " + minDiff + " min " + secDiff + " Secs " ;

setTimeout(showtime,1000);

}



</script>
<div id='display'></div>
<body onload ="showtime()">
</body>
</html>

Mike H.
10-21-2008, 12:18 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">

var refDate = new Date('2009 December 4 12:00')
var GMToffset = -5; // Your current GMT offset;
var preMsg = "Message prior to the date";
var postMsg = "Message after the date";

function update(){

var currDate = new Date();
currDate.setHours(GMToffset+currDate.getHours()+currDate.getTimezoneOffset()/60);
if (refDate > currDate){document.getElementById('message').innerHTML = preMsg}
else {document.getElementById('message').innerHTML = postMsg}
var remTime = refDate-currDate;
if (remTime < 0){remTime = remTime * -1};
var nDays = parseInt(remTime/86400000);
var nHours = parseInt((remTime-(nDays*86400000))/3600000);
var nMin = parseInt((remTime-(nDays*86400000)-(nHours*3600000))/60000);
var nSec = 0;
if (refDate > currDate){nSec = 60-(currDate.getSeconds())}
else {nSec = currDate.getSeconds()}
var nYears = parseInt(nDays/365);
var nMonths = parseInt((nDays-(nYears*365))/30);
var rDays = parseInt((nDays-(nYears*365)-(nMonths*30)));
document.getElementById('display').innerHTML = nYears + " Years, " + nMonths + " Months, " + rDays +
" Days, " + nHours + " Hours, " + nMin + " Minutes, " + nSec + " Seconds";
setTimeout("update()",1000);
}

onload = update;

</script>
<style type="text/css">

body {background-color: #eae3c6; margin-top: 60px;}
form {width: 710px; margin: auto; font-family: 'times new roman'; font-size: 12pt;}
fieldset {width: auto; padding-left: 10px; padding-bottom: 10px; background-color: #f0fff0; border: 1px solid #87ceeb;}
legend {font-family: 'times new roman'; font-size: 12pt; color: #00008b; background-color: #87ceeb; padding-left: 3px; padding-right: 3px; margin-bottom: 5px;}
#message {width: 300px; margin-left: auto; margin-right: auto; margin-bottom: 10px; text-align: center; font-family: 'times new roman'; font-size: 14pt; color: #00008b; background-color: #87ceeb;}
#display {width: 550px; margin-left: auto; margin-right: auto; margin-bottom: 10px; text-align: center; font-family: 'times new roman'; font-size: 12pt; color: #00008b; background-color: #87ceeb;}

</style>
</head>
<body>
<div id='message'></div>
<div id='display'></div>
</body>
</html>