问题描述
我正在从我的数据库中获取一个项目列表,每个项目都有一个 CURRENT_TIMESTAMP,在 时间之前.所以这很好.但问题是我还想在不到 30 分钟的物品上贴上新"横幅.我如何获取生成的时间戳(例如:2012-07-18 21:11:12)并说明它是否距离当前时间不到 30 分钟,然后在该项目上回显NEW"横幅.
I'm getting a list of items from my database, each has a CURRENT_TIMESTAMP which i have changed into 'x minutes ago' with the help of timeago. So that's working fine. But the problem is i also want a "NEW" banner on items which are less than 30 minutes old. How can i take the generated timestamp (for example: 2012-07-18 21:11:12) and say if it's less than 30 minutes from the current time, then echo the "NEW" banner on that item.
推荐答案
使用strtotime("-30 minutes") 然后看看你的行的时间戳是否大于那个.
Use strtotime("-30 minutes") and then see if your row's timestamp is greater than that.
例子:
<?php
if(strtotime($mysql_timestamp) > strtotime("-30 minutes")) {
$this_is_new = true;
}
?>
我在这里使用 strtotime() 两次来获取您的 mysql 日期的 unix 时间戳,然后再次获取 30 分钟前的时间戳.如果 30 分钟前的时间戳大于 mysql 记录的时间戳,那么它一定是在 30 分钟前创建的.
I'm using strtotime() twice here to get unix timestamps for your mysql date, and then again to get what the timestamp was 30 minutes ago. If the timestamp from 30 mins ago is greater than the timestamp of the mysql record, then it must have been created more than 30 minutes go.
这篇关于PHP检查时间戳是否小于30分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)