How to calculate hour:minutes from total minutes?

心已入冬 提交于 2019-12-19 18:24:27

问题


For example i have 525 minutes, if we will divide it by 60 the result will be 8.75

But 1 hour have only 60 minutes not 75

How can i calculate the exact hour:minutes from total minutes?


回答1:


$hours = intval($totalMinutes/60);
$minutes = $totalMinutes - ($hours * 60);

Edited to be PHP




回答2:


This kind of conversion is done using integer division and the modulo operator. With integer division you find out how many of the "large" unit you have and with modulo you find out how many of the "small" unit are left over:

define('MINUTES_PER_HOUR', 60);

$total_minutes = 525;
$hours = intval($total_minutes / MINUTES_PER_HOUR);  // integer division
$mins = $total_minutes % MINUTES_PER_HOUR;           // modulo

printf("%d minutes is really %02d:%02d.\n", $total_minutes, $hours, $mins);

See it in action.




回答3:


floor(525 / 60) gives the number of hours (8.75 rounded down to 8).

525 % 60 gives the number of minutes (modulo operator).




回答4:


What I did for my girl friend made her chart with 60 min intervals eg 1=60,2=120,3=180,4=240,5=300,6=360 etc etc. then I told her to get her minutes eg 337 find the closest number without going over that would be 5 then use the number 5 equals and subtract it from your original minutes 337-300=37 the remainder is the minutes thus 337 minutes equals 5 hours and 37 minutes



来源:https://stackoverflow.com/questions/7931935/how-to-calculate-hourminutes-from-total-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!