|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Need help with to change Javascript Count Down
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, Code:
<
$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>
<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>
|
|
#2
|
|||
|
|||
|
Just change the code that sets innerText value to this:
Code:
if (hh >= 0) {
document.all["clock"].innerText = hh + " Hours " + mm + " Minutes " + ss + " Seconds";
}
Output should be like this: 4Hours 32 Minutes 35 Seconds |
|
#3
|
|||
|
|||
|
This did not change my countdown format, still displays format 00:00:00 Seconds
|
|
#4
|
|||
|
|||
|
I should have mentioned that the Count Down time is set in the HTML as well, here it is,
Code:
$expiredate = "2008-12-22";
$expiretime = "10:46";
$exptime = explode(":",$expiretime);
$expdate = explode("-",$expiredate);
$expiretimestamp = mktime($exptime[0],$exptime[1],0,$expdate[1],$expdate[2],$expdate
[0],-1);
$seconds_left = $expiretimestamp - time();
|
|
#5
|
|||
|
|||
|
This HTML page displays time in the format you need. Play with it.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<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.getElementById("clock").innerHTML = '';
this.location.href = this.location.href;
}
var mm = sourcedate.getMinutes();
var ss = sourcedate.getSeconds();
if (hh >= 0) {
document.getElementById("clock").innerHTML = hh + " Hours " + mm + " Minutes " + ss + " Seconds";
}
}
sourcedate = new Date();
//-->
</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>
I used document.getElementById("clock") 'caz it's a crossbrowser way to get some element by its identifier. Also i replaced innerText by innerHTML - not all browsers implement innerText property |
|
#6
|
|||
|
|||
|
This doesn't display the days which is really what I am after sorry,
|
|
#7
|
|||
|
|||
|
Any one able to help me display the Days as well as hours, minutes and seconds remaining?
Thanx in advanced |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Need help with to change Javascript Count Down |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|