计算剩余时间的php自定义函数一例
时间:2021-07-01 10:21:17
帮助过:15人阅读
/** - * 计算剩余时间
- * by bbs.it-home.org
- */
public function gettime($time_s,$time_n){ - $time_s = strtotime($time_s);
- $time_n = strtotime($time_n);
- $strtime = '';
- $time = $time_n-$time_s;
- if($time >= 86400){
- return $strtime = date('Y-m-d H:i:s',$time_s);
- }
- if($time >= 3600){
- $strtime .= intval($time/3600).'小时';
- $time = $time % 3600;
- }else{
- $strtime .= '';
- }
- if($time >= 60){
- $strtime .= intval($time/60).'分钟';
- $time = $time % 60;
- }else{
- $strtime .= '';
- }
- if($time > 0){
- $strtime .= intval($time).'秒前';
- }else{
- $strtime = "时间错误";
- }
- return $strtime;
- }
|