在我的項(xiàng)目中,我需要將日期時(shí)間舍入,例如“08:10”到“08:00”。更多例子"8:20 到 8:15" "8:31 到 8:30"在下一步中,我需要一個(gè)額外的方法來進(jìn)行匯總。例如“8:20 到 8:30”“8:31 到 8:45”$shiftInPre = new \DateTime($row["time_start"] /* <-e.g. 8:02*/);echo roundtoLastQuarterHour($shiftInPre);
2 回答

jeck貓
TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
如果您只有H:i而不是完整的日期時(shí)間,請(qǐng)使用基本的字符串操作
$shiftInPre = '8:07';
list($hours, $mins) = explode(':', $shiftInPre);
$mins = $hours * 60 + $mins;
$rounded = round($mins / 15) * 15;
echo floor($rounded / 60) . ':' . str_pad($rounded % 60, 2, 0);
// 8:07 >> 8:00
// 8:08 >> 8:15
// 8:18 >> 8:15
- 2 回答
- 0 關(guān)注
- 196 瀏覽
添加回答
舉報(bào)
0/150
提交
取消