<?phpfunction time2units ($time) {$year = floor ($time/60/60/24/365); $time-= $year * 60 * 60 * 24 * 365; $month = Floor ($time/60/60/24/30); $time-= $month * 60 * 60 * 24 * 30; $week = Floor ($time/60/60/24/7); $time-= $week * 60 * 60 * 24 * 7; $day = Floor ($time/60/60/24); $time-= $day * 60 * 60 * 24; $hour = Floor ($time/60/60); $time-= $hour * 60 * 60; $minute = Floor ($time/60); $time-= $minute * 60; $second = $time; $elapse = "; $UNITARR = Array (' Year ' = ' + ' Years ', ' month ' = ' ' month ', ' Week ' = ' ' Week ', ' Day ' = ' ~ ', ' hour ' = ' hour ', ' Minutes ' = ' minute ', ' sec ' = ' second '); foreach ($unitArr as $CN = + $u) {if ($ $u > 0) {$elapse = $ $u. $CN; Break }} return $elapse;} $past = 1462866257; Some timestamp in the Past$now = Time (); Current Timestamp$diff = $now-$past; Echo ' Posted in '. Time2units ($diff) . ' former ';? >
Php Time Method (also good)