简体   繁体   English

此表达式如何工作? ($ variable / 60)%60

[英]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.

相关问题 这条 cookie 行是什么意思? (时间()+1*24*60*60;) - What does this cookie line mean? (time()+1*24*60*60;) 表达式中的变量赋值如何工作? - How does variable assignment in an expression work? 如何将Facebook访问令牌延长至60天 - how to extend facebook access token to 60 days 如何在 MySQL 数据库中存储 60 个布尔值? - How to store 60 Booleans in a MySQL Database? range(strtotime(“00:00”), strtotime(“23:59”), 30*60) laravel升级到7后不能正常工作。是php的问题吗? - range(strtotime(“00:00”), strtotime(“23:59”), 30*60) does not work properly after upgrade laravel to 7. Is it php problem? 如何计算php中2个unix时间戳之间的间隔而不除以86400(60 * 60 * 24) - How to calculate the interval between 2 unix timestamps in php WITHOUT dividing by 86400 (60*60*24) 如何在MySQL中获取0-30天的记录,30-60和60 -90以及90以上 - How to get 0-30 days record, 30-60 and 60 -90 and above 90 in mysql Wordpress cUrl 错误 60 和 77 - 似乎没有任何效果 - Wordpress cUrl error 60 and 77 - Nothing seems to work 未定义的变量:第60行中的用户NULL Phalcon - Undefined variable: user in view on line 60 NULL Phalcon 将int 60转换为60分钟的时间值 - Convert int 60 to a time value of 60 minutes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM