当前位置:Gxlcms > PHP教程 > 计算剩余时间的php自定义函数一例

计算剩余时间的php自定义函数一例

时间:2021-07-01 10:21:17 帮助过:15人阅读

  1. /**

  2. * 计算剩余时间
  3. * by bbs.it-home.org
  4. */

  5. public function gettime($time_s,$time_n){

  6. $time_s = strtotime($time_s);
  7. $time_n = strtotime($time_n);
  8. $strtime = '';
  9. $time = $time_n-$time_s;
  10. if($time >= 86400){
  11. return $strtime = date('Y-m-d H:i:s',$time_s);
  12. }
  13. if($time >= 3600){
  14. $strtime .= intval($time/3600).'小时';
  15. $time = $time % 3600;
  16. }else{
  17. $strtime .= '';
  18. }
  19. if($time >= 60){
  20. $strtime .= intval($time/60).'分钟';
  21. $time = $time % 60;
  22. }else{
  23. $strtime .= '';
  24. }
  25. if($time > 0){
  26. $strtime .= intval($time).'秒前';
  27. }else{
  28. $strtime = "时间错误";
  29. }
  30. return $strtime;
  31. }

人气教程排行