0, "days" =>">
当前位置:Gxlcms > PHP教程 > PHP将秒数转换为时间(年、月、日、小时…)

PHP将秒数转换为时间(年、月、日、小时…)

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

这个有用的函数能将秒数表示的事件转换为年、月、日、小时等时间格式

  1. function Sec2Time($time){
  2. if(is_numeric($time)){
  3. $value = array(
  4. "years" => 0, "days" => 0, "hours" => 0,
  5. "minutes" => 0, "seconds" => 0,
  6. );
  7. if($time >= 31556926){
  8. $value["years"] = floor($time/31556926);
  9. $time = ($time%31556926);
  10. }
  11. if($time >= 86400){
  12. $value["days"] = floor($time/86400);
  13. $time = ($time%86400);
  14. }
  15. if($time >= 3600){
  16. $value["hours"] = floor($time/3600);
  17. $time = ($time%3600);
  18. }
  19. if($time >= 60){
  20. $value["minutes"] = floor($time/60);
  21. $time = ($time%60);
  22. }
  23. $value["seconds"] = floor($time);
  24. return (array) $value;
  25. }else{
  26. return (bool) FALSE;
  27. }
  28. }

转换为, PHP, 将秒数

人气教程排行