使用PHP将当前时间汇总到最接近的15分钟

时间:2014-05-22 11:37:59

标签: php time

有没有一种简单的方法可以获得当前时间并将其四舍五入到下一刻钟?

例如,如果是12:36则显示12:45 如果它的13:01然后显示13:15

1 个答案:

答案 0 :(得分:5)

这是你的答案

$current_date = date('d-M-Y g:i:s A');
echo $current_date."<br/>";
$current_time = strtotime($current_date);

$frac = 900;
$r = $current_time % $frac;

$new_time = $current_time + ($frac-$r);
$new_date = date('d-M-Y g:i:s A', $new_time);

echo $new_date."<br/>";

<强> LIVE DEMO

相关问题