現在の時間と最も近い時間をどのように取得しますか。
今がその時です2:25PM
。
現在の時間は2:00PM
最も近い時間です2:59PM
(そう3PM
で2:59PM
はありません)。
You can use the date function :
$current = date("g:00A");
$next = date("g:59A");
If you want the real time :
$now = date("g:iA");
If I understand correctly:
<?php
$hour = date("g:00A"); // or "G" for 24-hour clock
$nearest_hour = date("g:59A");
?>
You can try something like this:
$hour = date('H');
$min = date('i');
if($min > 30)
{
$closest_hour = $hour +1;
}
elseif($min < 30)
{
$closest_hour = $hour;
}
else
{
//Here is exactly half past $hour so you decide what to do :)
}
HTH!
So you have HH:MM.
Why just keep HH and add 59 next to it ? Isn't that work all the time ?