Ниже приведено очень простое и чрезвычайно эффективное решение.
function timeElapsed($originalTime){
$timeElapsed=time()-$originalTime;
/*
You can change the values of the following 2 variables
based on your opinion. For 100% accuracy, you can call
php's cal_days_in_month() and do some additional coding
using the values you get for each month. After all the
coding, your final answer will be approximately equal to
mine. That is why it is okay to simply use the average
values below.
*/
$averageNumbDaysPerMonth=(365.242/12);
$averageNumbWeeksPerMonth=($averageNumbDaysPerMonth/7);
$time1=(((($timeElapsed/60)/60)/24)/365.242);
$time2=floor($time1);//Years
$time3=($time1-$time2)*(365.242);
$time4=($time3/$averageNumbDaysPerMonth);
$time5=floor($time4);//Months
$time6=($time4-$time5)*$averageNumbWeeksPerMonth;
$time7=floor($time6);//Weeks
$time8=($time6-$time7)*7;
$time9=floor($time8);//Days
$time10=($time8-$time9)*24;
$time11=floor($time10);//Hours
$time12=($time10-$time11)*60;
$time13=floor($time12);//Minutes
$time14=($time12-$time13)*60;
$time15=round($time14);//Seconds
$timeElapsed=$time2 . 'yrs ' . $time5 . 'months ' . $time7 .
'weeks ' . $time9 . 'days ' . $time11 . 'hrs '
. $time13 . 'mins and ' . $time15 . 'secs.';
return $timeElapsed;
}
echo timeElapsed (1201570814);
Выход образца:
6yrs 4months 3weeks 4 дня 12 часов 40 минут и 36 секунд.