: This article mainly introduces the php time function, which is ready for use. if you are interested in the PHP Tutorial, please refer to it.
Function tranTime ($ time) {$ rtime = date ("m-d H: I", $ time); $ htime = date ("H: I", $ time ); $ time = time ()-$ time; if ($ time <60) {$ str = 'hangzhou';} 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 ago '. $ htime;} elseif ($ time <60*60*24*3) {$ d = floor ($ time/(60*60*24 )); if ($ d = 1) $ str = 'Yesterday '. $ rtime; else $ str = 'day before yesterday '. $ rtime;} else {$ str = $ rtime;} return $ str ;}
Function get_countdown ($ unix_time = '') {if (empty ($ unix_time) return false; if ($ unix_time <time () return array (" day "=> 0, "hour" => 0, "min" => 0, "sec" => 0); $ timediff = $ unix_time-time (); $ days = intval ($ timediff/86400); // calculate the time difference for the whole day $ remain = $ timediff % 86400; // Obtain the remainder of the total number of days, the remaining seconds are recorded as A $ hours = intval ($ remain/3600); // calculate the entire hour by dividing A by 3600 $ remain = $ remain % 3600; // use the remainder of the hour for A division as B $ mins = intval ($ remain/60); // calculate the entire score by dividing 60 with B $ secs = $ remain % 60; // use the integer B to divide the remainder into the remaining seconds $ res = array ("day" => $ days, "hour" => $ hours, "min" => $ mins, "sec" => $ secs); return $ res ;}
The above introduces the php time function, that is, the out-of-the-box function, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.