如何检查是否时间戳是一个小时了? [英] How to check if a timestamp is an hour old?
问题描述
我建立一个缓存系统来存储Twitter的API鸣叫,以避免违反每小时呼叫限制。
I am building a caching system to store Twitter API tweets as to avoid violating the hourly call limit.
我储存的tweet与时间戳的数据库,然后在PHP检查,看看是否时间戳是一个小时的时候,这样的话我再次调用API。此刻我似乎无法得到它的工作。以下是我有curently有(这点我承认很可能是错的!)
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. 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!
推荐答案
怎么样使用时间戳减去3600?
What about using the timestamp minus 3600?
if($results->tweet_date <= time() - 3600) {
//do api call
} else {
//call tweets from database
}
编辑:如果你想使用的strtotime
,您可以用的strtotime(' - 1小时的)
来算算时间(介意小时而不是小时)。
If you want to use strtotime
, you can use strtotime('-1 hour')
to calculate the time (mind the hour instead of hours).
这篇关于如何检查是否时间戳是一个小时了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!