在我的项目中,我需要将日期时间舍入,例如“08:10”到“08:00”。更多例子"8:20 到 8:15" "8:31 到 8:30"在下一步中,我需要一个额外的方法来进行汇总。例如“8:20 到 8:30”“8:31 到 8:45”$shiftInPre = new \DateTime($row["time_start"] /* <-e.g. 8:02*/);echo roundtoLastQuarterHour($shiftInPre);
2 回答
jeck猫
TA贡献1909条经验 获得超7个赞
如果您只有H:i而不是完整的日期时间,请使用基本的字符串操作
$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 关注
- 176 浏览
添加回答
举报
0/150
提交
取消