简体   繁体   English

如何检查时间戳是否一小时?

[英]How to check if a timestamp is an hour old?

I am building a caching system to store Twitter API tweets as to avoid violating the hourly call limit. 我正在建立一个缓存系统来存储Twitter API推文,以避免违反每小时的通话限制。

I am storing the tweets in a database with a timestamp and then checking in PHP to see if the timestamp is an hour old, if so then I call the API again. 我将推文存储在带有时间戳的数据库中,然后检查PHP以查看时间戳是否为一小时,如果是,那么我再次调用API。 At the moment I can't seem to get it working. 目前我似乎无法让它发挥作用。 Here is what I curently have (which I admit is most probably wrong!) 这就是我所拥有的(我承认这很可能是错的!)

 if($results->tweet_date <= strtotime('-1 hours')) {
 //do api call
 } else {
 //call tweets from database
 } 

This doesn't seem to be working though. 这似乎不起作用。 Can anyone point me in the right direction? 谁能指出我正确的方向? Thanks! 谢谢!

What about using the timestamp minus 3600? 使用时间戳减去3600怎么样?

if($results->tweet_date <= time() - 3600) {
//do api call
} else {
//call tweets from database
} 

EDIT: If you want to use strtotime , you can use strtotime('-1 hour') to calculate the time (mind the hour instead of hours). 编辑:如果你想使用strtotime ,你可以使用strtotime('-1 hour')来计算时间(记住小时而不是小时)。

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

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