I have a php date, and i want the difference about php date and today's date.
The code is:
function countdown(counter, year, month, day, hour, minute, second){
var datePhp = new Date(year, month, day, hour, minute, second);
var today=new Date();
var days=0;
var hours=0;
var minutes=0;
var seconds=0;
var sumeDays = 0;
if (datePhp>today){
var difference=(datePhp.getTime()-today.getTime())/1000;
days=Math.floor(difference/86400);
difference=difference-(86400*days);
if(days==1){
sumeDays=days*24;
}
hours=Math.floor(difference/3600);
printHours=Math.floor(difference/3600)+sumeDays;
difference=difference-(3600*hours);
minutes=Math.floor(difference/60);
difference=difference-(60*minutes);
seconds=Math.floor(difference);`
$("#counter" + counter).html(printHours + ' Hours ' + minutes + ' Minutes ' + seconds + ' Seconds');
if (days>0 || hours>0 || minutes>0 || seconds>0){
setTimeout("countdown("+counter+", "+year+","+month+","+day+","+hour+","+minute+","+second+")",1000)
}
The code runs, but runs wrong, because always say less than 24 hours. For example, if phpDate is 4/06/2014 09:30 (where 4 is the European day and 6 is June) and today is 2/06/2014 09:30 (where 2 is the European day and 6 is June). The code say that there are only 24 hours to phpDate.
And the code in html is:
<div id='counter<?php echo $i ?>'></div>
<script type="text/javascript">
countdown(<?php echo $i?>, <?php echo $year?>, <?php echo $month?>, <?php echo $day?>, <? php echo $hour?>, <?php echo $minute?>, <?php echo $second?>);
</script>
console.log(new Date())
console.log(datePhp)
to your question, this will help to see the problem, as it may e.g. be a timezone problem. – t.niese