Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- static public function humanTimeDiff($from, $to, $precise=true) {
- $difference = $to - $from;
- $periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade");
- $lengths = array("60","60","24","7","4.35","12","10");
- for($j = 0; $difference >= $lengths[$j]; $j++) { $mod = $difference%$lengths[$j]; $difference /= $lengths[$j]; }
- $difference = round($difference);
- if($difference != 1) $periods[$j].= "s";
- $text = "$difference ".(($difference!=1)?($periods[$j]."s"):$periods[$j]);
- if($precise && $mod > 0) $text .= " ".$mod." ".(($mod!=1)?($periods[($j-1)]."s"):$periods[($j-1)]);
- return $text;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement