繁体   English   中英

在PHP中创建日,时,分和秒倒计时

[英]Create Day, Hour, Minute and Second countdown in PHP

到目前为止,我已经有了一个可以计算天数和小时数的脚本,但是如何使它也可以数分钟和数秒呢?

$remaining = strtotime($ActiveListing['ListingExpires']) - time();
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);

我想到了date()的解决方案:

$remaining = strtotime($ActiveListing['ListingExpires']) - time();
list($months, $days, $hours, $minutes, $seconds) = explode(" ",date("n j H i s",$remaining));
$months--;$days--;
echo "$months months - $days days - $hours hours - $minutes minutes - $seconds seconds left";
$remaining         = strtotime($ActiveListing['ListingExpires']) - time();
$days_remaining    = floor($remaining/60/60/24);
$hours_remaining   = floor(($remaining-($days_remaining*60*60*24))/60/60);
$minutes_remaining = floor(($remaining-($days_remaining*60*60*24)-($hours_remaining*60*60))/60);
$seconds_remaining = floor(($remaining-($days_remaining*60*60*24)-($hours_remaining*60*60))-($minutes_remaining*60));
$edate = '2027-07-06 07:01:53';
$datestr = $edate;//Your date
$date=strtotime($datestr);//Converted to a PHP date (a second count)
//Calculate difference
$diff=$date-time();//time returns current time in seconds
$days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day)
$hours=round(($diff-$days*60*60*24)/(60*60)); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM