PHP general function, PHP Universal
1 /**2 * Time axis function, Unix timestamp3 * @param int $time time4 */5 functionTrantime ($time) {6 //$time = Strtotime ($time);7 $nowTime= Time (); 8 $message= ''; 9 //a year agoTen if(Idate(' Y ',$nowTime) !=Idate(' Y ',$time )) { One $message=Date(' Y year m D Day ',$time ); A } - Else { - //same year the $days=Idate(' Z ',$nowTime) -Idate(' Z ',$time ); - Switch(true){ - //in one day - Case(0 = =$days): + $seconds=$nowTime-$time; - //within one hour + if($seconds< 3600) { A //in a minute . at if($seconds< 60) { - if(3 >$seconds) { - $message= ' Just '; -}Else { - $message=$seconds. ' Seconds ago '; - } in } - $message=intval($seconds/60). ' Minutes ago '; to } + $message=Idate(' H ',$nowTime) -Idate(' H ',$time) . ' Hour ago '; - Break; the //Yesterday * Case(1 = =$days): $ $message= ' Yesterday '.Date(' H:i ',$time );Panax Notoginseng Break; - //The day before the Case(2 = =$days): + $message= ' The day before yesterday '.Date(' H:i ',$time ); A Break; the //within 7 days + Case(7 >$days): - $message=$days. ' Days ago '; $ Break; $ //more than 7 days - default: - $message=Date(' N-month J-Day H:i ',$time ); the Break; - }Wuyi } the return $message; -}
http://www.bkjia.com/PHPjc/969883.html www.bkjia.com true http://www.bkjia.com/PHPjc/969883.html techarticle PHP general functions, PHP Universal 1/* * 2 * Timeline function, Unix timestamp 3 * @param int $time Time 4 */5 function Trantime ($time) {6//$time = STRT Otime ($time); 7 $nowTime = t ...