E.G。如果我希望当前日期有15分钟的飞跃: 如果现在是:
2017-2-2 18:22
15分钟的跳跃时间将是:
2017-2-2 18:30
如果现在是:
2017-2-2 18:30
15分钟的跳跃时间将是:
2017-2-2 18:30
如果现在是:
2017-2-2 18:31
15分钟的跳跃时间将是:
2017-2-2 18:45
15:01到30:00给30:00,30:01到45:00给45:00等...
答案 0 :(得分:0)
解决方案是:
public function minutesToQuarterHour($timestring) {
$minutes = date('i', strtotime($timestring));
return ($minutes - ($minutes % 15) + 15);
}
$time = '2016-10-04 15:59:00'; ///or any date get with carbon->now()
$minutes = minutesToQuarterHour($time);
$dateBase = Carbon::parse($time);
$dateBase = Carbon::parse($dateBase->format("Y-m-d H" . ':00:00'))->addMinutes($minutes);
echo $dateBase->format("Y-m-d H:i");