添加15分钟到当前时间并按15分钟间隔

Vim*_*ath 5 php datetime

我需要在当前时间增加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;
Run Code Online (Sandbox Code Playgroud)

Pau*_*xon 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";
Run Code Online (Sandbox Code Playgroud)

您看起来可能想要在最后一个间隔添加2*$间隔,但您应该能够根据您的需要进行调整.

  • OMG有人读了这个问题.请大夫! (7认同)
  • 我看到了不好的答案,不得不跳进来:) (2认同)