2017-06-03 55 views
0

我需要一個代碼來檢測當前時間並給我下面的時間什麼是可以被五整除的。PHP時間:得到下一分鐘/小時什麼是可以被5整除

例如:這是:06 03,2017 21:22:23,給我06 03,2017 21:25:00在PHP。 我沒有任何想法開始。有沒有任何代碼或解決方案來做到這一點?

+0

使用'日期'獲取當前分鐘。然後得到模5。 –

回答

1
$now = time(); 
// Add five minutes in seconds, round it down to the nearest five: 
$next = ceil($now/300)*300; 
echo date('H:i', $next); 
0

找到當前分鐘的5和模的差值。然後將此添加到當前時間。例如:

$now = intval(date('i')); 
$minutesToAdd = 5 - $now % 5; 
$nextTime = date('m d, Y H:i:00', strtotime("+$minutesToAdd minutes")); 
echo $nextTime; 

也許這不是完美的解決方案,但shuld工作,也爲情況下,像13點59分(模是4,5-4 = 1,59 + 1 = 00)。