如果大家有更好的方案欢迎交流
function diffBetweenTwoDay($pastDay){ $timeC = time() - strtotime($pastDay); $dateC = round((strtotime(date(‘Y-m-d‘)) - strtotime(date(‘Y-m-d‘,strtotime($pastDay))))/60/60/24); if($timeC<=3*60){ $dayC = ‘刚刚‘; }elseif($timeC>3*60&&$timeC<=5*60){ $dayC = ‘3分钟前‘; }elseif($timeC>5*60&&$timeC<=10*60){ $dayC = ‘5分钟前‘; }elseif($timeC>10*60&&$timeC<=30*60){ $dayC = ‘10分钟前‘; }elseif($timeC>30*60&&$timeC<=60*60){ $value[‘addtime‘] = ‘30分钟前‘; }elseif($timeC>60*60&&$timeC<=120*60){ $dayC = ‘1小时前‘; }elseif($timeC>120*60&&$dateC == 0){ $dayC = ‘今天‘; }elseif($dateC == 1){ $dayC = ‘昨天‘; }else{ $dayC = date(‘Y-m-d‘,strtotime($value[‘addtime‘])); } return $dayC; }
时间: 2024-12-06 00:13:42