如何在特定位置找出特定日期时间的时区?

时间:2011-12-22 20:49:00

标签: php timezone

我在其他国家/地区的活动日期需要保存在数据库中。问题是那些日期没有包含时区信息。

此位置使用的时区为CET(标准时间)或CEST(夏令时)。

检测哪一个正在发挥作用的最简单方法是什么?

2 个答案:

答案 0 :(得分:3)

我不太确定你在问什么。我你需要知道的是特定日期是否在夏令时。如果是,您可以使用date('I')

$dst_now = date('I'); // whether our current timezone is currently in DST
$dst_then = date('I', strtotime($date)); // whether that date is in DST for our current timezone

$date_obj = new DateTime($date, new DateTimeZone('Europe/Paris'));
$dst_thereandthen = $date_obj->format('I');
// whether that date is in DST for that timezone

如果你需要的不是这些,请澄清你需要的......

答案 1 :(得分:1)

我认为date_default_timezone_get()函数会为您提供所需的信息,但我并不完全确定它可以区分标准/夏令时。

date_default_timezone_get()