【问题标题】:PHP increase seconds value, roll-around 60PHP增加秒值,滚动60
【发布时间】:2012-09-27 11:43:16
【问题描述】:

如何增加变量中的秒数?

增加一个日期..:

date("m/d/Y h:i:s a", time() + 30);

但我想这样做:

$seconds = 59;
$increase = 3;
$result = $seconds + $increase; // 62

我希望它在 60 秒前停止并重新计算,结果应该是 2 而不是 60

【问题讨论】:

  • 使用模数(整数除法后的余数)。 $result = ($seconds + $increase) % 60;

标签: php date format int


【解决方案1】:

你想要取模运算符:

$seconds = 59;
$increase = 3;
$result = ($seconds + $increase) % 60; // 2

【讨论】:

    猜你喜欢
    • 2017-07-24
    • 2018-10-04
    • 1970-01-01
    • 2016-09-19
    • 2016-12-16
    • 2018-10-10
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多