Convert seconds to time


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

URL: http://www.catswhocode.com/blog/10-super-useful-php-snippets

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.