Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何检查时间是否已过期?_Php - Fatal编程技术网

Php 如何检查时间是否已过期?

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函数实现这个功能

//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);

如果($dateExpire
date
接受一个格式说明符,如
H:i:s
,并返回一个按照该说明符格式化的日期字符串。数字在该格式中不起任何作用,因此
date('2018-05-24')
只返回
“2018-05-24“
原样……在PHPs中有一些示例,您使用
=
/