Advertisement
AbdulMuttaqin

a.php

Jul 23rd, 2021
1,484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.23 KB | None | 0 0
  1.  <?php  
  2.  date_default_timezone_set('Asia/Jakarta');
  3.  
  4.  echo facebook_time_ago('2021-07-23 04:58:00');  
  5.  
  6.  function facebook_time_ago($timestamp)  
  7.  {  
  8.       $time_ago = strtotime($timestamp);  
  9.       $current_time = time();  
  10.       $time_difference = $current_time - $time_ago;  
  11.       $seconds = $time_difference;  
  12.       $minutes      = round($seconds / 60 );           // value 60 is seconds  
  13.       $hours           = round($seconds / 3600);           //value 3600 is 60 minutes * 60 sec  
  14.       $days          = round($seconds / 86400);          //86400 = 24 * 60 * 60;  
  15.       $weeks          = round($seconds / 604800);          // 7*24*60*60;  
  16.       $months          = round($seconds / 2629440);     //((365+365+365+365+366)/5/12)*24*60*60  
  17.       $years          = round($seconds / 31553280);     //(365+365+365+365+366)/5 * 24 * 60 * 60  
  18.       if($seconds <= 60)  
  19.       {  
  20.      return "Baru Saja";  
  21.    }  
  22.       else if($minutes <=60)  
  23.       {  
  24.      if($minutes==1)  
  25.            {  
  26.        return "1 menit yang lalu";  
  27.      }  
  28.      else  
  29.            {  
  30.        return "$minutes menit yang lalu";  
  31.      }  
  32.    }  
  33.       else if($hours <=24)  
  34.       {  
  35.      if($hours==1)  
  36.            {  
  37.        return "beberapa jam yang lalu";  
  38.      }  
  39.            else  
  40.            {  
  41.        return "$hours jam yang lalu";  
  42.      }  
  43.    }  
  44.       else if($days <= 7)  
  45.       {  
  46.      if($days==1)  
  47.            {  
  48.        return "kemarin";  
  49.      }  
  50.            else  
  51.            {  
  52.        return "$days hari yang lalu";  
  53.      }  
  54.    }  
  55.       else if($weeks <= 4.3) //4.3 == 52/12  
  56.       {  
  57.      if($weeks==1)  
  58.            {  
  59.        return "seminghu yang lalu";  
  60.      }  
  61.            else  
  62.            {  
  63.        return "$weeks minggu lalu";  
  64.      }  
  65.    }  
  66.        else if($months <=12)  
  67.       {  
  68.      if($months==1)  
  69.            {  
  70.        return "sebulan yang lalu";  
  71.      }  
  72.            else  
  73.            {  
  74.        return "$months bulan yang lalu";  
  75.      }  
  76.    }  
  77.       else  
  78.       {  
  79.      if($years==1)  
  80.            {  
  81.        return "setahun yang lalu";  
  82.      }  
  83.            else  
  84.            {  
  85.        return "$years tahun yang lalu";  
  86.      }  
  87.    }  
  88.  }  
  89.  ?>  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement