【发布时间】: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;