PHP comparing UNIX timestamps

柔情痞子 提交于 2020-01-05 06:56:28

问题


I've having an issue comparing two unix timestamps in php.

$time_now = mktime();
if($auction->time_end > $time_now){
   //true
}
else{
   //false
}

$auction->time_end is 1362579127 and set as int from db. $time_now is for example 1364129253 and is set as int, both were checking with var_dump and are indeed returning both as ints.

The problem is that PHP seems to think 1362579127 is greater than 1364129253 (returns false) which it is not.. am I missing something here? If I input the values into the if statement it works as it should but when it's comparing the object it doesn't seem to like it.


回答1:


Looking at your question it seems you have the logic the wrong way around. The current time is always bigger then a time in the past. Try the following:

if($time_now>$auction->time_end){
//...
}



回答2:


The maximum of the int type is defined to be around 2 billion if you're on a 32Bit system. Both of your numbers seem to be too big. See the Documentation.



来源:https://stackoverflow.com/questions/15598729/php-comparing-unix-timestamps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!