[英]PHP Laravel, how to check if string date and time is not in the past
I want to check if date and time where stored in the session are not in the past and greater than 15 minutes of the current time我想检查存储在 session 中的日期和时间是否不是过去的并且是否大于当前时间的 15 分钟
$time = Session::get('preorder_time');
$date = Session::get('preorder_date');
ex.前任。
$date = "2020-08-15"; $date = "2020-08-15";
$time = "21:30"; $time = "21:30";
I want to check if this time and date plus 15 minutes greater than current time我想检查这个时间和日期是否比当前时间大 15 分钟
use carbon:使用碳:
if(\Carbon\Carbon::parse($date.' '.$time)->addMinutes(15)->gt(\Carbon\Carbon::now())
{
//your code
}
Pretty much all builtin date functions can parse that format, so:几乎所有内置日期函数都可以解析该格式,因此:
$date = "2020-08-15";
$time = "21:30";
if (strtotime("$date $time") + 15*60 < time()) {
} else {
}
To inspect the value:检查值:
var_dump(date('r', strtotime("$date $time")));
string(31) "Sat, 15 Aug 2020 21:30:00 +0200"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.