PHP 格式时间方法
最近处理了一些将时间 (Y-m-d格式) 转化成天,小时,分钟的问题,发现很有用,总结一下分享
function fix_time_for_data($dateTime){
$nowTime = time();
$datetime = $nowTime-strtotime($dateTime);
$days = round(($datetime) / 3600 / 24);
if($days < 1){
$hour = round($datetime / 3600);
if($hour < 1){
$minute = round($datetime / 60);
echo $minute.' minutes ago';
}else{
echo $hour.' hours ago'
}
}else{
echo $days.' days ago';
}
}