如何将时间分为半小时和一小时?

I am trying to round the provided value to half hour and hour.

$Total_Minutes = 5 // should be 30 minutes
$Total_Minutes = 29 // should be 30 minutes
$Total_Minutes = 31 // should be 1 hour or 60 minutes
$Total_Minutes = 61 // should be 1 and half-hour or 90 minutes

Is this possible to get such kind of result by function?

you can round it to the next multiple of 30:

<?php

$arr = array(5, 29, 31, 61);
foreach($arr as $val){
    echo floor(($val + 29) / 30) * 30;
    echo "
";
}
//produces 30, 30, 60, 90
?>
if($Total_Minutes%30>0)
    $Total_Minutes = ($Total_Minutes - ($Total_Minutes%30)) + 30;

Hi , Try this

echo ceil($minutes/30)*30 .'minutes';

This is pseudo code as I don't have access to a php compiler at the time of writing, but this will do the job.

$remainder = $Total_Minutes % 60;
if($remainder <= 30 && $remainder > 0)
{
   $Remainder = 30;
}
else
{
   if($remainder != 0)
   {
      $remainder = 60;
   }
}