Advertisement
cos8o

getGJTime

Jan 12th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. function getGJTime($timestamp) {
  3. $ts = $timestamp;
  4. $cts = time();
  5. $str = "";
  6. $result = $cts-$ts;
  7. if ($result < 31556952) {
  8. if ($result < 2629746) {
  9. if ($result < 86400) {
  10. if ($result < 3600) {
  11. if ($result < 60) {
  12. $n = $result/1;
  13. if ($n == 1){
  14. $str = " second";
  15. }else{
  16. $str = " seconds";
  17. }
  18. $final = $n.$str;
  19. }else{
  20.  $n = floor($result/60);
  21. if ($n == 1){
  22. $str = " minute";
  23.   }else{
  24.   $str = " minutes";
  25. }
  26. $final = $n.$str;
  27.  }
  28.             }else{
  29.             $n = floor($result/3660);
  30.             if ($n == 1){
  31.                     $str = " hour";
  32.                     }else{
  33.                     $str = " hours";
  34.                     }
  35.                     $final = $n.$str;
  36.             }
  37.         }else{
  38.         $n = floor($result/86400);
  39.         if ($n == 1){
  40.                     $str = " day";
  41.                     }else{
  42.                     $str = " days";
  43.                     }
  44.                     $final = $n.$str;
  45.         }
  46.     }else{
  47.     $n = floor($result/2629746);
  48.     if ($n == 1){
  49.                     $str = " month";
  50.                     }else{
  51.                     $str = " months";
  52.                     }
  53.                     $final = $n.$str;
  54.     }
  55. }else{
  56. $n = floor($result/31556952);
  57. if ($n == 1){
  58.                     $str = " year";
  59.                     }else{
  60.                     $str = " years";
  61.                     }
  62.                     $final = $n.$str;
  63. }
  64. return $final;
  65. }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement