sharkblue
04-07-2004, 01:25 AM
Hello!
Basically I have a countdown script which counts down to a specific date. It consists of php and javascript, php is used only to get servers time and not user's computer time.
Currently the output looks like this let's say "58:12", 58 are minutes and 12 are seconds. there are no hours in the output.
---------------------------
Here is what I want
there are 0 to 59 seconds equal to 1 minutes, what I want is only 20 seconds to equal to 1 minutes. So once 20 seconds passes it goes one minute down and so on.... Please tell me how to do that. Below is my php page with scripts
p.s. sorry for my english, not my first language
-------------------------------
<?php
// Setup the expire date/time
$expiredate = "2005-08-30";
$expiretime = "20:58";
// calculate seconds to expire date/time
$exptime = explode(":",$expiretime);
$expdate = explode("-",$expiredate);
$expiretimestamp = mktime($exptime[0],$exptime[1],0,$expdate[1],$expdate[2],$expdate
[0],-1);
$seconds_left = $expiretimestamp - time();
// has expire date/time passed?
$countdown = ($seconds_left >= 0) ? true : false;
?>
<html>
<head>
<title>COUNTDOWN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if ($countdown) // if the expire date/time hasn't been reached
{
?>
<script language="JavaScript">
<!--
function showtime() {
setTimeout("showtime();",1000);
sourcedate.setTime(sourcedate.getTime()-1000);
var hh = (sourcedate.getDate()-1)*24 + sourcedate.getHours()-1;
if ( hh < 0 ) {
document.all["clock"].innerText = '';
this.location.href = this.location.href; // Reload the page
}
var mm = sourcedate.getMinutes();
var ss = sourcedate.getSeconds();
if (hh >= 0) {
document.all["clock"].innerText = ((mm < 10) ? "0" : "") + mm + ((ss < 10) ? ":0" : ":") + ss;
}
}
sourcedate = new Date(<?= date("Y,m,d,H,i,s",$seconds_left);?>);
//-->
</script>
<?php
} // end if ($countdown)
?>
</head>
<body>
<?php
if ($countdown) // if the expire date/time hasn't been reached
{
?>
<span name="clock" id="clock" class="top_tbl"></span>
<?php
}
else // Show some other content
{
?>
We have passed the expiredate/time: <?= $expiredate . ' ' . $expiretime; ?>
<?php
}
?>
<script language="JavaScript">
<!--
showtime(); // Init the function
//-->
</script>
</body>
</html>
Basically I have a countdown script which counts down to a specific date. It consists of php and javascript, php is used only to get servers time and not user's computer time.
Currently the output looks like this let's say "58:12", 58 are minutes and 12 are seconds. there are no hours in the output.
---------------------------
Here is what I want
there are 0 to 59 seconds equal to 1 minutes, what I want is only 20 seconds to equal to 1 minutes. So once 20 seconds passes it goes one minute down and so on.... Please tell me how to do that. Below is my php page with scripts
p.s. sorry for my english, not my first language
-------------------------------
<?php
// Setup the expire date/time
$expiredate = "2005-08-30";
$expiretime = "20:58";
// calculate seconds to expire date/time
$exptime = explode(":",$expiretime);
$expdate = explode("-",$expiredate);
$expiretimestamp = mktime($exptime[0],$exptime[1],0,$expdate[1],$expdate[2],$expdate
[0],-1);
$seconds_left = $expiretimestamp - time();
// has expire date/time passed?
$countdown = ($seconds_left >= 0) ? true : false;
?>
<html>
<head>
<title>COUNTDOWN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if ($countdown) // if the expire date/time hasn't been reached
{
?>
<script language="JavaScript">
<!--
function showtime() {
setTimeout("showtime();",1000);
sourcedate.setTime(sourcedate.getTime()-1000);
var hh = (sourcedate.getDate()-1)*24 + sourcedate.getHours()-1;
if ( hh < 0 ) {
document.all["clock"].innerText = '';
this.location.href = this.location.href; // Reload the page
}
var mm = sourcedate.getMinutes();
var ss = sourcedate.getSeconds();
if (hh >= 0) {
document.all["clock"].innerText = ((mm < 10) ? "0" : "") + mm + ((ss < 10) ? ":0" : ":") + ss;
}
}
sourcedate = new Date(<?= date("Y,m,d,H,i,s",$seconds_left);?>);
//-->
</script>
<?php
} // end if ($countdown)
?>
</head>
<body>
<?php
if ($countdown) // if the expire date/time hasn't been reached
{
?>
<span name="clock" id="clock" class="top_tbl"></span>
<?php
}
else // Show some other content
{
?>
We have passed the expiredate/time: <?= $expiredate . ' ' . $expiretime; ?>
<?php
}
?>
<script language="JavaScript">
<!--
showtime(); // Init the function
//-->
</script>
</body>
</html>