PHP Checking if timestamp is less than 30 minutes old(PHP检查时间戳是否小于30分钟)
问题描述
我正在从我的数据库中获取一个项目列表,每个项目都有一个 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分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP检查时间戳是否小于30分钟


基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01