如何比较这个日期和时间
15 AUGUST at 8:00 PM IST ( GMT + 5:30)
转换为当前日期和时间15 AUGUST at 8:00 PM IST ( GMT + 5:30)
此日期存储在数据库中,需要与当前时间进行比较,如果当前时间少15分钟,则需要启动我的逻辑。
$dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$classDate = explode(' ', '27 AUGUST at 8:00 PM IST ( GMT + 5:30)');
$currentDate = explode(' ',date("d F")." at ".$dateTime->format("h:i A").' '.'IST ( GMT + 5:30)');
if ($currentDate['0'] == $classDate['0']) {
if ($currentDate['1'] == $classDate['1']) {
if ($currentDate['4'] == $classDate['4']) {
$minutes = (strtotime($classDate['3']) - strtotime($currentDate['3']))/60;
if ($minutes <= 15 && $minutes >= 0) {
echo "Your class is ready, Join now";
}
}
}
}
Here i have exploded the dates and compared the date month as well compared time
converting to `strtotime()` and boom.......