我有一个 php 日期,我想要关于 php 日期和今天日期的区别。代码为: function countdown(counter, year, month, day, hour, minute, second){
var datePhp = new Date(year, month, day, hour, minute, second); var 今天=新日期();变天= 0; var小时=0;var分钟=0;变量秒=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)
}
代码运行,但运行错误,因为总是说不到 24 小时。例如,如果 phpDate 是 4/06/2014 09:30(其中 4 是欧洲日,6 是六月),而今天是 2/06/2014 09:30(其中 2 是欧洲日,6 是六月)。代码说phpDate只有24小时。
html中的代码是:
<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>