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分钟


- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 仓库 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01