简体   繁体   English

比较并检查PHP Date()

[英]Comparing and checking PHP Date()

I'm trying to figure out how to compare against date() . 我试图弄清楚如何与date()进行比较。 I'm following along in a tutorial about how to use this function to compare the current time against the time a cache file was last modified. 我将继续学习有关如何使用此功能将当前时间与上次修改缓存文件的时间进行比较的教程。 In the tutorial, the author uses "10800" as 3 hours and the code looks something like: 在本教程中,作者使用“ 10800”作为3个小时,代码如下所示:

(filemtime($cache) < (time()-10800)) (filemtime($ cache)<(time()-10800))

I have no problem understanding how this comparison works but I just don't get how the the expression of time, "10800" , is formatted. 我毫无疑问地理解了这种比较是如何进行的,但是我只是不明白时间表达“ 10800”是如何格式化的。

Just for the record I spent a solid 15 minutes looking for an answer so I'm not just being ignorant of Google haha. 仅出于记录目的,我花了整整15分钟时间寻找答案,因此我不仅对Google哈哈一无所知。

Thanks! 谢谢!

10800 is in seconds.. 10800在几秒钟内..

all unix timestamps are measured in seconds since the epoch... 1 being the first second of 1970. 自epoch ...以来的所有unix时间戳都以秒为单位... 1是1970年的第一秒。

This explains why when you have a bad strtotime value and you are interpreting it with date ie 这解释了为什么当您的strtotime值不正确并且要用日期来解释它时,即

date(strtotime("last tomorrowday"));

it ends up showing you 1969-12-31 ... strtotime is returning 0 and if 1 is the first second of 1970 then 0 will be interpreted as the last second of 1969 它最终向您显示1969-12-31 ... strtotime返回0,如果1是1970年的第一秒,则0将被解释为1969年的最后一秒

It's in seconds, 在几秒钟内

3 hours = 3 * 60 * 60 = 10800 seconds

As time function returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). As time函数返回自Unix纪元(1970年1月1日00:00:00 GMT)以来以秒为单位的当前时间。 You neeed to subtract 10800 from it to get timestamp of time before 3 hours . 您需要从中减去10800以获得3 hours之前的时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM