/ Published in: PHP
URL: http://bettesmidler.com/code/2009-08-11.htm
Expand |
Embed | Plain Text
function getTimeDiff($timestamp=false) { if ($timestamp) { // Determine the difference, between the time now and the timestamp $difference = $current_time - $timestamp; // Set the periods of time // Determine which period we should use, based on the number of seconds lapsed. // If the difference divided by the seconds is more than 1, we use that. // Go from decades backwards to seconds for ( ($val >= 0) && (($number = $difference / $lengths[$val]) <= 1); $val-- ); // Ensure the script has found a match if ($val < 0) $val = 0; // Determine the minor value, to recurse through $new_time = $current_time - ($difference % $lengths[$val]); // Set the current value to be floored // If required create a plural if ($number != 1) $periods[$val] .= "s"; // Return text return $text; } }
You need to login to post a comment.
