Php 如何检查时间是否已过期?
如何检查持续时间是否超过当前日期/时间?我不知道如何用date函数实现这个功能Php 如何检查时间是否已过期?,php,Php,如何检查持续时间是否超过当前日期/时间?我不知道如何用date函数实现这个功能 //date item was put up for sale $start_date = date("2018-05-24"); //time it was put up for sale $start_time = date('08:37:19'); //The duration the item should be up until $duration = date('2018-05-25 09.00.00
//date item was put up for sale
$start_date = date("2018-05-24");
//time it was put up for sale
$start_time = date('08:37:19');
//The duration the item should be up until
$duration = date('2018-05-25 09.00.00');
要获取当前日期,只需使用参数中带有格式的
date
函数:
日期(“Y-m-d H:i:s”)
之后,您只需将当前日期与日期进行比较
这里有一些例子:
date(“Y-m-d”)==$start\u date
(返回true
)
date(“Y-m-d H:i:s”)<$duration
(返回false
)编辑:
试试这个:
if (strtotime(date("Y-m-d H:i:s")) >= strtotime(date('Y-m-d H:i:s', strtotime("$start_date $start_time")) && strtotime(date("Y-m-d H:i:s")) <= strtotime($duration)) {
return true;
} else {
return false;
}
if(strotime(date)(“Y-m-dh:i:s”)>=strotime(date('Y-m-dh:i:s',strotime($start\u date$start\u time”)&&strotime(date)(“Y-m-dh:i:s”)更容易使用时间戳
$startTime = strtotime('2015-01-01 00:00:00');
$dateExpire = strtotime('+5 day', $startTime);
if($dateExpire <= time()) {
return 'expired';
}
$startTime=strotime('2015-01-01 00:00:00');
$dateExpire=strottime(“+5天”,$startTime);
如果($dateExpiredate
接受一个格式说明符,如H:i:s
,并返回一个按照该说明符格式化的日期字符串。数字在该格式中不起任何作用,因此date('2018-05-24')
只返回“2018-05-24“
原样……在PHPs中有一些示例,您使用=
/