How to check if a timestamp is an hour old?

爱⌒轻易说出口 提交于 2019-12-25 08:54:01

问题


I am building a caching system to store Twitter API tweets as to avoid violating the hourly call limit.

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!


回答1:


What about using the timestamp minus 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).



来源:https://stackoverflow.com/questions/12403189/how-to-check-if-a-timestamp-is-an-hour-old

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!