我正在抓一个希腊网站参加某些活动并获得EEST时区的活动时间(这是他们当地时间)。 现在我在我的数据库中创建了一些事件,并且我将UNIX_TIMESTAMP存储为日期时间。
我需要将已删除的EEST时间转换为我当地时间(IST)并在时间周期内转换。 然后我需要检查两者是否相同。如果是这样,我将插入刮刮数据。
为此,我使用的是一个函数,但两个时间戳在任何给定的日期都不匹配。请告诉我我做错了什么或我该怎么做!
public function date_convert($dt, $tz1, $df1, $tz2, $df2) {
$res = '';
if(!in_array($tz1, timezone_identifiers_list())) { // check source timezone
trigger_error(__FUNCTION__ . ': Invalid source timezone ' . $tz1, E_USER_ERROR);
} elseif(!in_array($tz2, timezone_identifiers_list())) { // check destination timezone
trigger_error(__FUNCTION__ . ': Invalid destination timezone ' . $tz2, E_USER_ERROR);
} else {
// create DateTime object
$d = DateTime::createFromFormat($df1, $dt, new DateTimeZone($tz1));
// check source datetime
if($d && DateTime::getLastErrors()["warning_count"] == 0 && DateTime::getLastErrors()["error_count"] == 0) {
// convert timezone
$d->setTimeZone(new DateTimeZone($tz2));
// convert dateformat
$res = $d->format($df2);
} else {
trigger_error(__FUNCTION__ . ': Invalid source datetime ' . $dt . ', ' . $df1, E_USER_ERROR);
}
}
return $res;
}
将其称为
echo $dt = self::date_convert('2014-08-05 15:30:00','Europe/Athens','Y-m-d H:i:s','Asia/Kolkata','Y-m-d H:i:s').'<br/>';
表格中相同日期(2014-08-05 18:00:00)的存储时间戳为1407241800
一些迭代:
日期(欧洲/雅典)----返回(亚洲/加尔各答)-----时间戳------存储时间戳
2014-08-05 15:30:00 ---- 2014-08-05 18:00:00 ----- 1407250800 ----- 1407241800
2014-05-01 12:30:00 ---- 2014-05-01 15:00:00 ----- 1398936600 ----- 1398945600