For example i have 525 minutes, if we will divide it by 60 the result will be 8.75
比如我有525分钟,如果除以60结果是8。75
But 1 hour have only 60 minutes not 75
但是1小时只有60分钟而不是75分钟。
How can i calculate the exact hour:minutes from total minutes?
我如何计算确切的小时数:从总分钟数到分钟数?
4 个解决方案
#1
13
$hours = intval($totalMinutes/60);
$minutes = $totalMinutes - ($hours * 60);
Edited to be PHP
编辑是PHP
#2
10
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);
看它的实际应用。
#3
2
floor(525 / 60)
gives the number of hours (8.75
rounded down to 8
).
楼层(525 / 60)给出小时数(8.75四舍五入到8)。
525 % 60
gives the number of minutes (modulo operator).
525%的60表示分钟数(模运算符)。
#4
1
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
我所做的我女朋友让她与60分钟间隔如图表1 = 60,2 = 120,3 = 180,4 = 240,5 = 300,6 = 360等等等等,然后我告诉她让她分钟如337找到最接近的数量不超过5然后使用的5号等于减去从原始分337 - 300 = 37其余分钟因此337分钟= 5小时37分钟
#1
13
$hours = intval($totalMinutes/60);
$minutes = $totalMinutes - ($hours * 60);
Edited to be PHP
编辑是PHP
#2
10
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);
看它的实际应用。
#3
2
floor(525 / 60)
gives the number of hours (8.75
rounded down to 8
).
楼层(525 / 60)给出小时数(8.75四舍五入到8)。
525 % 60
gives the number of minutes (modulo operator).
525%的60表示分钟数(模运算符)。
#4
1
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
我所做的我女朋友让她与60分钟间隔如图表1 = 60,2 = 120,3 = 180,4 = 240,5 = 300,6 = 360等等等等,然后我告诉她让她分钟如337找到最接近的数量不超过5然后使用的5号等于减去从原始分337 - 300 = 37其余分钟因此337分钟= 5小时37分钟