php 时间

$t = time(); $t1 = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));//(当天凌晨0点);是Int TO_DAYS(NOW()) - TO_DAYS(events.add_time) >7; events.add_time是String类型; function feed_related_time( $t, $o='' ) //$t是int 返回时间间隔 { $obj = array( 0=>array('5*60'=>'剛剛'), 1=>array('60*60'=>'%m分鐘前'), 2=>array('24*60*60'=>'%h小時前'), 3=>array('7*24*60*60'=>'%d天前'), 4=>array('30*24*60*60'=>'%w周前'), 5=>array('365*24*60*60'=>'%F月前'), 6=>array('50*365*24*60*60'=>'%y年前')); $timestamp = $t; $nowstamp = time(); $passedTime = $nowstamp - $timestamp; $m = ceil($passedTime / 60); $h = ceil($passedTime / (60*60)); $d = ceil($passedTime / (24*60*60)); $w = ceil($passedTime / (7*24*60*60)); $f = ceil($passedTime / (30*24*60*60)); $y = ceil($passedTime / (365*24*60*60)); if ($o == '') { $o = $obj; } for($i=0; $i<count($o); $i++) { $ret = ''; $max = key($o[$i]); eval('$timeAge = '.$max.';'); $ret = current($o[$i]); if ( $passedTime < $timeAge) { $ret = current($o[$i]); $ret = str_replace("%m",$m, $ret); $ret = str_replace("%h",$h, $ret); $ret = str_replace("%d",$d, $ret); $ret = str_replace("%w",$w, $ret); $ret = str_replace("%F",$f, $ret); $ret = str_replace("%y",$y, $ret); break; } } return $ret; }

 

 

你可能感兴趣的:(php 时间)