php - 如何将这个日期和时间 8 月 15 日下午 8:00 IST (GMT + 5:30) 与 PHP 中的当前日期和时间进行比较
问题描述
如何比较这个日期和时间
15 AUGUST at 8:00 PM IST ( GMT + 5:30)
到 PHP 中的当前日期和时间,
15 AUGUST at 8:00 PM IST ( GMT + 5:30)
此日期存储在 db 中,需要与当前时间进行比较,如果当前时间少 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.......
推荐阅读
- android - RecyclerView 无法应用于 FlexboxLayoutManager
- linux - Vimwiki C-Enter 或 S-Enter 在 Gnome 终端中不起作用
- php - 如何让我的 WordPress 导航链接显示出来?
- angular - Angular 和 AngularFire | 传递变量 - 例子/好的参考?
- python - 如何将定义的函数应用于 Python 中的数组?
- python - 如何检查字典列表中的某个字段是否相等?
- python - 如何将节点属性从 NetworkX 传递到散景
- python - 家长 | 子 DataFrame 到平衡的层次结构
- python-3.x - Python数字格式
- typescript - 如何在带有 Jest 的 React Native 项目中使用 __mocks__