Guest User

Untitled

a guest
Jun 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. function duration($seconds, $displaySeconds = 1, $displayMinutes = 1, $displayHours = 1) {
  2.         $time['days'] = (int) $seconds / 86400 % 86400;
  3.         $time['hours'] = (int) $seconds / 3600 % 24;
  4.         $time['minutes'] = (int) $seconds / 60 % 60;
  5.         $time['seconds'] = (int) $seconds % 60;
  6.  
  7.         $string = '';
  8.         if ($time['days'] > 0) {
  9.                 $string .= $time['days'] . (($time['days'] == 1) ? ' day ' : ' days ');
  10.         }
  11.         if ($displayHours == 0) { return empty($string) ? '0 days' : $string; }
  12.  
  13.         if ($time['hours'] > 0) {
  14.                 $string .= $time['hours'] . (($time['hours'] == 1) ? ' hour ' : ' hours ');
  15.         }
  16.         if ($displayMinutes == 0) { return empty($string) ? '0 hours' : $string; }
  17.  
  18.         if ($time['minutes'] > 0) {
  19.                 $string .= $time['minutes'] . (($time['minutes'] == 1) ? ' minute ' : ' minutes ');
  20.         }
  21.         if ($displaySeconds == 0) { return empty($string) ? '0 minutes' : $string; }
  22.  
  23.         if ($time['seconds'] > 0) {
  24.                 $string .= $time['seconds'] . (($time['seconds'] == 1) ? ' second ' : ' seconds ');
  25.         }
  26.  
  27.         $string = trim($string);
  28.         return empty($string) ? '0 hours' : $string;
  29. }
Add Comment
Please, Sign In to add comment