嗨我想从这个函数中排除sat和sun。目前这是计算所有天数
function human_timing_mins_hrs_days_only($time)
{
$time = time() - $time; // to get the time since that moment
$tokens = array (
86400 => 'day',
3600 => 'hour',
60 => 'min',
0 => 'min'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
}
}
答案 0 :(得分:0)
您可以使用datetime对象尝试:
function human_timing_mins_hrs_days_only($time)
{
$now = new DateTime();
$dateInThePast = (new DateTime)->setTimestamp($time);
$interval = $now->diff($dateInThePast, true);
$sundays = intval($interval->days / 7) + ($now->format('N') + $interval->days % 7 >= 7);
$saturdays = intval($interval->days / 7) + ($now->format('N') + $interval->days % 6 >= 6);
$tokens = array (
'days' => 'day',
'h' => 'hour',
'i' => 'min',
);
$units = 0;
$text = 'mins';
foreach ($tokens as $property => $name) {
if ($interval->$property === 0) {
continue;
}
$units = $property === 'days' ? $interval->$property - ($sundays + $saturdays) : $interval->$property;
$text = $name . ($units > 1 ? 's' : '');
}
return $units . ' ' . $text;
}
请注意,此代码未经过测试,可能需要进行一些更新才能使其正常运行。