PHP - 比较日期,检查是否在最近一小时内 [英] PHP - Comparing date, checking if within last hour
问题描述
$ unit_date = date($ unit ['last_accessed'],'Y-m-d H:i:s');
$ last_hour = date('Y-m-d H:i:s',strtotime(' - 1小时));
if($ unit_date> = $ last_hour){
$ connect =< i class ='fa fa-circle 2x'style ='color:#2ECC71;'> < / i>;
} else {
$ connect ='';
}
正如你所看到的,我把$ unit ['last_accessed']放入正确的格式,然后比较一个小时前。如果时间是在最后一个小时内,连接是一个字体真棒圈(彩色绿色),如果不是在最后一小时内它是空的,现在说没有什么是在最后一小时内是假的。
if(time() - strtotime($ unit ['last_accessed'])< 3601){
或
if(time() - strtotime($ unit ['last_accessed'])> 3599){
time()和strtotime()都使用相同的时基(以秒为单位)
如果$ unit ['last_accessed']已经是整数时间变量那么不要使用strtotime()。
I'm attempting to see if a time is within the last hour.
$unit_date = date($unit['last_accessed'], 'Y-m-d H:i:s');
$last_hour = date('Y-m-d H:i:s', strtotime('-1 hour'));
if($unit_date >= $last_hour ){
$connect = "<i class='fa fa-circle 2x' style='color:#2ECC71;'></i>";
} else {
$connect = '';
}
As you can see I'm putting $unit['last_accessed'] into the correct format then comparing to an hour ago. If the time is within the last hour $connect is a font awesome circle (colored green), if it's not within the last hour it's empty, right now it's saying nothing is within the last hour which is false.
if(time() - strtotime($unit['last_accessed']) < 3601){
or
if(time() - strtotime($unit['last_accessed']) > 3599){
time() and strtotime() both use the same time base in seconds
if $unit['last_accessed'] is already an integer time variable then do not use strtotime().
这篇关于PHP - 比较日期,检查是否在最近一小时内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!