I believe that some articles published on many websites will show that this article was published several seconds ago or a few months ago, next, I will introduce how long it takes to calculate the time difference between the posting time and the current time using php computing.
| The Code is as follows: |
Copy code |
|
<? Php
/**
* Time Difference Calculation
*/
Function time2Units ($ time)
{
$ Year = floor ($ time/60/60/24/365 );
$ Time-= $ year * 60x60*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' => 'Year', 'month' => 'month', 'Week' => 'Week ', 'day' => 'day ',
'Hour '=> 'hour', 'mine' => 'minute ', 'second' => 'second'
);
Foreach ($ unitArr as $ cn => $ u)
{
If ($ u> 0)
{
$ Elapse =$ u. $ cn;
Break;
}
}
Return $ elapse;
}
$ Past = 2052345678; // Some timestamp in the past
$ Now = time (); // Current timestamp
$ Diff = $ now-$ past;
Echo 'posted in'. time2Units ($ diff ';
?> |