affc Posted March 22, 2008 Share Posted March 22, 2008 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 https://forums.phpfreaks.com/topic/97348-plz-help-to-change-javascript-count-down-to-include-days/ Share on other sites More sharing options...
Psycho Posted March 23, 2008 Share Posted March 23, 2008 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 https://forums.phpfreaks.com/topic/97348-plz-help-to-change-javascript-count-down-to-include-days/#findComment-498683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.