Compteur de temps pour vente flash
Bonjour,
Il y a ce code pré-installé pour gérer un compteur de temps pour une vente flash d'un produit. Le compteur est bien affiché mais il ne s'actualise que si on actualise la page. Je voudrais que le compteur s'actualise tout seul à chaque seconde. il y a le <script> qui est déactivé avec la syntaxe /* mais même si j'enleve le /* pour l'activé le paramètre
Code:
setInterval('cur_time('+end+');',1000);
ne semble pas fonctionner. Alors comment corriger ce code ? Merci d'avance
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| <?php
$date1 = $project['end_date'];
//echo $project['end_date'];
$date2 = date('Y-m-d h:i:s');
$diff = abs(strtotime($date1) - strtotime($date2));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
//echo "<br>".$years."<br>";
//echo $months."<br>";
//echo $days."<br>";
$day1 = floor($diff/ (60*60*24));
$hours = floor(($diff - $day1*60*60*24)/ (60*60));
$minuts = floor(($diff - $day1*60*60*24 - $hours*60*60)/ 60);
$seconds = floor(($diff - $day1*60*60*24 - $hours*60*60 - $minuts*60));
date('d', strtotime($project['end_date']));
if($day1 < 10) $day1 = '0'.$day1;
if($hours < 10) $hours = '0'.$hours;
if($minuts < 10) $minuts = '0'.$minuts;
if($seconds < 10) $seconds = '0'.$seconds;
/*echo "<br>days=".$day1."<br>";
echo "<br>days=".$hours."<br>";
echo "<br>days=".$minuts."<br>";
echo "<br>days=".$seconds."<br>";
die();*/
?>
<script>
/*function update_cur_time(t1,t2)
{
var end = new Date(t1);
var cur = new Date(t2);
var loc = new Date();
end = end.getTime();
cur = cur.getTime();
loc = loc.getTime();
var temp = cur - loc;
end = end - temp;
setInterval('cur_time('+end+');',1000);
}
function cur_time(end)
{
var loc = new Date();
loc = loc.getTime();
var diff = end - loc;
var dd = Math.floor(diff / (1000*60*60*24));
var hh = Math.floor((diff - (1000*60*60*24*dd)) / (1000*60*60));
var mm = Math.floor((diff - (1000*60*60*24*dd) - (1000*60*60*hh)) / (1000*60));
var ss = Math.floor((diff - (1000*60*60*24*dd) - (1000*60*60*hh) - (1000*60*mm)) / (1000));
if(dd < 10){ dd = '0' + dd; }
if(hh < 10){ hh = '0' + hh; }
if(mm < 10){ mm = '0' + mm; }
if(ss < 10){ ss = '0' + ss; }
if(dd==00 && hh==00 && mm==00 && ss==00){
clearInterval();
}
document.getElementById('update_day').innerHTML = dd;
document.getElementById('update_hour').innerHTML = hh;
document.getElementById('update_minute').innerHTML = mm;
document.getElementById('update_second').innerHTML = ss;
}*/
</script> |