Jump to content

Plz Help to change Javascript Count Down to include DAYS


affc

Recommended Posts

Hello,

 

I would like to change the display of this count down from looking like this: 93:42:34 Seconds

 

I want it to include a Day, something like: 4 Days 12 Hours 32 Seconds, if anyone could help that would be awesome, the code itself works fine just want to change how it is displayed in Explorer,

 

<html>
<head>
<title>Count Down</title>
<?php
$expiredate = "$year-$month-$day";
$expiretime = "$hour:$min";

$exptime = explode(":",$expiretime);
$expdate = explode("-",$expiredate);
$expiretimestamp = mktime($exptime[0],$exptime[1],0,$expdate[1],$expdate[2],$expdate
[0],-1);
$seconds_left = $expiretimestamp - time();

$countdown = ($seconds_left >= 0) ? true : false;
?>

<script language="JavaScript">
<!--
function showtime() {        
setTimeout("showtime();",1000);
sourcedate.setTime(sourcedate.getTime()-1000);
var hh = (sourcedate.getDate()-1)*24 - 9 + sourcedate.getHours()-1;
if ( hh < 0 ) {
document.all["clock"].innerText = '';
this.location.href = this.location.href;
}
var mm = sourcedate.getMinutes();
var ss = sourcedate.getSeconds();
if (hh >= 0) {
document.all["clock"].innerText = ((hh < 10) ? "0" : "") + hh + ((mm < 
10) ? ":0" : ":") + 
mm + ((ss < 10) ? ":0" : ":") + ss;
}
}

sourcedate = new Date(<?= date("Y,m,d,H,i,s",$seconds_left);?>);
//-->
</script>
</head>
<body>
<font color="black" size="2" face="Times New Roman, Times, serif">Time Remaining: </font><font color="red" size="2" face="Times New Roman, Times, serif">
<span name="clock" id="clock" class="top_tbl">Countdown 
                      here</span> Seconds</font>
<script language="JavaScript">
<!--
showtime();
//-->
</script>
</body>
</html>

Link to comment
Share on other sites

If I am understaning what the script is supposed to be doing, it is not generating the correct time. Here is one way to accomplish a countdown in the format you asked:

<script language="JavaScript">
<!--

var day_unit = 86400000;
var hour_unit = 3600000;
var minute_unit = 60000;
var second_unit =  1000;

function showtime() {      

    nowTime = new Date();

    if (sourcedate>nowTime) setTimeout("showtime();",1000)

    date_diff = sourcedate - nowTime;

    days = Math.floor(date_diff/day_unit);
    date_diff = date_diff - days * day_unit;
    hours = Math.floor(date_diff/hour_unit);
    date_diff = date_diff - hours * hour_unit;
    minutes = Math.floor(date_diff/minute_unit);
    date_diff = date_diff - minutes * minute_unit;
    seconds = Math.floor(date_diff/second_unit);

    time_remain = days+' Days '+hours+' Hours '+minutes+' Minutes '+seconds+' Seconds';
    document.all["clock"].innerText = time_remain;

    return;

}

sourcedate = new Date(2008, 2, 24, 5, 5, 5);
//-->
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.