5

現在の時刻に 15 分を追加する必要があります。例: 今は 20:48、15 分を追加する必要があるため、今は になりますが21:03、21:15 に設定する必要があります。つまり、の倍数にする必要があり15,30,45,00ます。ヘルプヘルプ/ガイダンスは役に立ちます。

<?php
$current_date_time = date('d/m/Y H:i:s');
$current_date = date("d/m/Y H:i", strtotime($current_date_time."+15 minutes"));
echo $current_date;exit;
4

4 に答える 4

15

ここに簡単な例があります

//what time is it?
$t=time();

//how long is our interval?
$interval=15*60;

//we can calculate when the last interval started by subtracting $t % $interval
$last = $t - $t % $interval;

//so now we know when the next interval will start...
$next = $last + $interval;

echo "Next interval at ".strftime('%H:%M:%S', $next)."\n";

最後の間隔に 2*$interval を追加したいように見えますが、これを自分に合わせて調整できるはずです。

于 2013-06-10T11:07:50.030 に答える
1
$current_date_time = date('d/m/Y H:i:s');
echo $current_date_time."<br>";
$current_date = date("d/m/Y H:i", strtotime($current_date_time."+15 minutes"));
echo $current_date."<br>";
$minutes = date("i",strtotime($current_date));
$min = '';
if($minutes > 0 && $minutes <15){
    $min = 15 - $minutes;
} else if($minutes > 15 && $minutes <30){
       $min = 30 - $minutes;
} else if($minutes > 30 && $minutes <45){
       $min = 45 - $minutes;
} else {
       $min = 59 - $minutes;
       $min++;
}

$newdate = date("d/m/Y H:i", strtotime($current_date."+".$min." minutes"));

echo $newdate;

上記のコードを使用します。これは私のために働いています。

于 2013-06-10T11:13:46.403 に答える