我在比较 php 中的两个 unix 时间戳时遇到问题.
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 是 1362579127 并从 db 设置为 int.例如,$time_now 是 1364129253 并设置为 int,两者都在检查 var_dump 并且确实以整数形式返回.
$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.
问题是 PHP 似乎认为 1362579127 大于 1364129253(返回 false),但事实并非如此.我在这里遗漏了什么吗?如果我将值输入到 if 语句中,它会正常工作,但是当它比较对象时,它似乎不喜欢它.
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.
推荐答案看着你的问题,你的逻辑似乎是错误的.当前时间总是大于过去时间.请尝试以下操作:
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){ //... }更多推荐
PHP 比较 UNIX 时间戳
发布评论