PublicstaticfunctiontimeFormatter ($ time) {$ dt_nowdate (Y-m-dH: I: s, time (); $ daysDateUtil: interVal (d, $ time, $ dt_now ); $ hoursDateUtil: interVal (h, $ time, $ dt_now); $ minutesDateUtil: interVal (n, $ time, $ dt_now); $ secondsD
Public static function timeFormatter ($ time) {$ dt_now = date ('Y-m-d H: I: s', time (); $ days = DateUtil :: interVal ("d", $ time, $ dt_now); $ hours = DateUtil: interVal ("h", $ time, $ dt_now); $ minutes = DateUtil :: interVal ("n", $ time, $ dt_now); $ seconds = D
Public static function timeFormatter ($ time) {$ dt_now = date ('Y-m-d H: I: s', time (); $ days = DateUtil :: interVal ("d", $ time, $ dt_now); $ hours = DateUtil: interVal ("h", $ time, $ dt_now); $ minutes = DateUtil :: interVal ("n", $ time, $ dt_now); $ seconds = DateUtil: interVal ("s", $ time, $ dt_now ); if ($ days = 0 & $ hours = 0 & $ minutes = 0) {return $ seconds. "seconds ago";} else if ($ days = 0 & $ hours = 0) {return $ minutes. "Minutes Ago";} else if ($ days = 0) {return "today ". date ("H: I", strtotime ($ time);} else {return date ("m month D day H: I", time ());}} public static function interVal ($ interval = "d", $ date1, $ date2) {$ timedifference = strtotime ($ date2)-strtotime ($ date1 ); $ days = bcp ($ timedifference, 86400); if ($ interval = 'D') {return $ days ;}$ temp1 = $ timedifference % (86400 ); $ hours = bcp ($ temp1, 3600); if ($ interval = 'H') {return $ hours;} $ temp2 = $ temp1 % (3600 ); $ minutes = bcp ($ temp2, 60); if ($ interval = 'n') {return $ minutes;} $ seconds = $ temp2 % 60; if ($ interval ='s ') {return $ seconds ;}}
Original article address: PHP implementation is similar to the release time of Sina Weibo. Thank you for sharing it with the original author.