The timeline development in php is very useful in development such as just five minutes ago and yesterday, such as forum posts, the bib has related applications. // The time conversion function functiontranTime ($ time) {$ rtime = date (m-dH: I, $ time); $ htime = date (H: i, $ time );
The timeline development in php is displayed as "just", "5 minutes ago", "Yesterday", etc.
It is quite useful during development, such as forum posts and collars.
- // Time conversion function
- Function tranTime ($ time ){
- $ Rtime = date ("m-d H: I", $ time );
- $ Htime = date ("H: I", $ time );
- $ Time = time ()-$ time;
- If ($ time <60 ){
- $ Str = 'gang ';
- }
- Elseif ($ time <60*60 ){
- $ Min = floor ($ time/60 );
- $ Str = $ min. 'minute ago ';
- }
- Elseif ($ time <60*60*24 ){
- $ H = floor ($ time/(60*60 ));
- $ Str = $ h. 'hour before '. $ htime;
- }
- Elseif ($ time <60*60*24*3 ){
- $ D = floor ($ time/(60*60*24 ));
- If ($ d = 1)
- $ Str = 'Yesterday '. $ rtime;
- Else
- $ Str = 'day before Day'. $ rtime;
- }
- Else {
- $ Str = $ rtime;
- }
- Return $ str;
- }
The $ time parameter in the tranTime () function must be a Unix Timestamp. if not, use strtotime () to convert it to a Unix timestamp.
Call the function and directly output the following:
- $times="1286861696 ";
- echo tranTime($times);