15分刻みにしたときの次回の時間を計算。応用して分刻みの時刻表も可能
public function calc_datetime ($margin_minutes=15) {
$timestamp = strtotime(date('Y-m-d H:i:s'));
// $timestamp = strtotime(date('Y-m-d H:i:s', strtotime('2023-01-01, 00:00:00'))); 時間指定する場合
$year = date('Y', $timestamp);
$month = date('m', $timestamp);
$day = date('d', $timestamp);
$hour = date('H', $timestamp);
$minute = date('i', $timestamp);
if($minute % $margin_minutes) {
$minute += $margin_minutes - ($minute % $margin_minutes);
} else {
$minute += $margin_minutes;
}
$datetime = date('Y-m-d H:i:s', mktime($hour, $minute, 0, $month, $day, $year));
return $datetime;
}