PHP 比较 UNIX 时间戳

编程入门 行业动态 更新时间:2024-10-10 04:19:36
本文介绍了PHP 比较 UNIX 时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在比较 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 时间戳

本文发布于:2023-05-25 19:52:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/236220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!