Home >Backend Development >PHP Problem >How to calculate remaining days in php
php method to calculate the remaining days: first create a PHP sample file; then use the "function ShengYu_Tian_Shi_Fen($unixEndTime=0){...}" method to calculate the remaining days.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to calculate the remaining days in php?
PHP implements the function to calculate the number of days, hours and minutes remaining
The code is as follows:
/** * 计算剩余天时分。 * $unixEndTime string 终止日期的Unix时间 * @author tangxinzhuan * @version 2016-10-28 */ function ShengYu_Tian_Shi_Fen($unixEndTime=0) { if ($unixEndTime <= time()) { // 如果过了活动终止日期 return '0天0时0分'; } // 使用当前日期时间到活动截至日期时间的毫秒数来计算剩余天时分 $time = $unixEndTime - time(); $days = 0; if ($time >= 86400) { // 如果大于1天 $days = (int)($time / 86400); $time = $time % 86400; // 计算天后剩余的毫秒数 } $xiaoshi = 0; if ($time >= 3600) { // 如果大于1小时 $xiaoshi = (int)($time / 3600); $time = $time % 3600; // 计算小时后剩余的毫秒数 } $fen = (int)($time / 60); // 剩下的毫秒数都算作分 return $days.'天'.$xiaoshi.'时'.$fen.'分'; }
Recommended learning: "PHP Video Tutorial 》
The above is the detailed content of How to calculate remaining days in php. For more information, please follow other related articles on the PHP Chinese website!