$endtime="2008-09-09 18:10:00";//date("Y-m-d H:i:s")格式
$d1=substr($endtime,17,2);//秒
$d2=substr($endtime,14,2);//分
$d3=substr($endtime,11,2);//时
$d4=substr($endtime,8,2);//日
$d5=substr($endtime,5,2);//月
$d6=substr($endtime,0,4);//年
$now_T=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));//$now_T=mktime();
$now_S=mktime("$d3","$d2","$d1","$d5","$d4","$d6");
$timeDiff['second']=intval($now_T-$now_S);
$timeDiff['mintue']=round($timeDiff['second']/60);//采用了四舍五入,可以修改
$timeDiff['hour']=round($timeDiff['mintue']/60);
$timeDiff['day']=round($timeDiff['hour']/24);
$timeDiff['week']=round($timeDiff['day']/7);
$timeDiff['month']=round($timeDiff['day']/30);//按30天来算
$timeDiff['year']=round($timeDiff['day']/365);//按365天来算
print_r($timeDiff)."
";
//数据库时间计算
SELECT DATEDIFF(NOW(),`timeItem`) FROM `table` WHERE 1;//得出日差
SELECT (datediff(NOW(),`timeItem`))*24+ (HOUR(NOW())-HOUR(`timeItem`)) FROM `table` WHERE 1//得出小时差
阅读(1074) | 评论(0) | 转发(0) |