PHP unix时间戳比较


PHP unix timestamp compare

我有一个事件日期&存储在我的数据库中的时间,该时间被保存为PHPunix时间戳。我想检查一下今天是否比活动日期和时间晚。

问题是,我试图使用当地时间(美国/纽约)进行检查,但我得到了两个不同的时区。time()显示在EST中,我的数据库显示在UTC 中

有什么方法可以正确检查吗?

数据库中的我的事件日期:1450447200(2015年12月18日下午2:00)

我试图将它与php time() 进行比较

我可能做错了吗?

*更新-答案*

根据这个答案,我最终做了这个:

$utc_str = gmdate("M d Y H:i:s", time());
$today = strtotime($utc_str);
$event_datetime = $Event_timestamp;
date_default_timezone_set("America/New_York");
$utc_str_event = gmdate("M d Y H:i:s", $event_datetime);
$event_date = strtotime($utc_str_event);
if($today >= $event_date){
    //Do Something
}

您可能在服务器上有错误的日期。time()应始终返回epoch(epoch=UTC)。

顺便说一句。在数据库中将日期保存为int这不是最佳做法

我不知道这是否正确,但您是否尝试过使用date_default_timezone_set