[英]How does this expression work? ($variable/60) % 60
I understand how modulus works. 我了解模数是如何工作的。 It gives the remainder of the number.
它给出了数字的其余部分。 So 482 % 60 would give 2.
所以482%60会给2。
Can someone explain to me this expression: 有人可以向我解释一下这个表达:
$minutes = ($seconds/60) % 60;
To me this says: 对我来说,这说:
if $seconds = 482
$minutes = (482/60) % 60
$minutes = (8.03333333333333) % 60
Then the result of that is 8. To me, it would have been simpler to leave out the % 60 part and just make 482/60 be an integer. 那么那的结果是8。对我来说,省略%60的部分并使482/60为整数会更简单。 And I don't understand how the % 60 is operating in this case.
而且我不了解%60在这种情况下的运行方式。
What am I missing? 我想念什么?
It gives you the minutes without the hours. 它为您提供分钟而无小时的信息。 Your example does not illustrate this as you are using seconds < 3600.
您的示例没有说明这一点,因为您使用的秒数<3600。
4000 seconds:
(seconds/60)%60
(4000/60)%60
(66.666)%60
6 minutes as a result. 结果是6分钟。 The 1 hour is calculated by another formula, most notably seconds/3600.
1小时是由另一个公式计算的,最值得注意的是秒/ 3600。
Consider if seconds was 3661. You would have one hour, one minute, one second. 考虑秒数是否为3661。您将有一个小时,一分钟,一秒钟。 Your formula would have minutes as 61.
您的公式的分钟数为61。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.