【发布时间】:2013-01-15 21:01:34
【问题描述】:
您好,我有一个特殊的时区,例如欧洲/柏林,我想在当前日期上增加 90 天。之后我检测到一个月的最后一天。
我在数据库中的日期以 UTC 格式保存。这就是为什么我必须在最后更改时区。
我的问题是,时区更改从欧洲/柏林和 UTC 之间的时间减去 2 小时。当我在将日期时间对象更改为 UTC 之前不修改它时,它只会减去 1 小时。谁能告诉我问题是什么或正确的解决方案?
//$timezone = 'Europe/Berlin';
private function getMaxTillDate($timezone)
{
$threemonth = new \DateTime('now', new \DateTimeZone($timezone) );
$threemonth->setTime(23, 59, 59);
$threemonth->add(new \DateInterval('P0Y90DT0H0M'));
$maxday = $threemonth->format('t');
$threemonth->setDate($threemonth->format('Y'), $threemonth->format('m'), $maxday);
$threemonth->setTimezone(new \DateTimeZone('UTC'));
return $threemonth;
}
非常感谢
【问题讨论】:
-
德国至少有半年时间实行夏令时,也就是UTC+2小时。
-
是的,我知道,但它没有描述如果我在更改时区之前不操作日期对象,为什么 php 只减去 1 小时。