我正在尝试制作一个实时处理的 BrowserGame,但我无法让系统计算 2 个时间戳之间的差异来工作,如果结果低于执行某些操作所需的时间,它会返回负数...
就像离线时添加资源一样,系统使用存储登录时间和注销时间的功能,下次用户登录时,它会计算时间差并计算用户获得多少资源..
但是资源返回负数..(EG:-1186、-54868、ETC)
谢谢阅读!
我正在尝试制作一个实时处理的 BrowserGame,但我无法让系统计算 2 个时间戳之间的差异来工作,如果结果低于执行某些操作所需的时间,它会返回负数...
就像离线时添加资源一样,系统使用存储登录时间和注销时间的功能,下次用户登录时,它会计算时间差并计算用户获得多少资源..
但是资源返回负数..(EG:-1186、-54868、ETC)
谢谢阅读!
<?php
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
?>
Taken straight from the DateTime class. http://php.net/manual/en/datetime.diff.php
If the time difference is negative, the first thing I think it could be would be that you have the arguments to your difference-finding function backwards.