我已浏览过关于SO的其他解决方案,它们都没有涉及以下方面的时区/ dst问题。时区和夏令时问题
我打电话给NOAA Tide Prediction API和NOAA National Weather Service API,需要传递时间范围才能检索数据。对于我的数据库中的每个位置,我都将UTC的时区作为UTC偏移量,以及是否观察到夏令时(1或0)。我试图将某些日期(今天和明天)格式化为LST(本地标准时间)在它自己的时区中,因此我可以传递给这些API。
我很难弄清楚如何知道日期(如今天)是否在夏时制范围内。
这是我到目前为止有:
// Get name of timezone for tide station
// NOTE: $locationdata->timezone is something like "-5"
$tz_name = timezone_name_from_abbr("", $locationdata->timezone * 3600, false);
$dtz = new DateTimeZone($tz_name);
// Create time range
$start_time = new DateTime('', $dtz);
$end_time = new DateTime('', $dtz);
$end_time = $end_time->modify('+1 day');
// Modify time to match local timezone
$start_time->setTimezone($dtz);
$end_time->setTimezone($dtz);
// Adjust for daylight savings time
if($locationdata->dst == '1')
{
// DST is observed in this area.
// ** HOW DO I KNOW IF TODAY IS CURRENTLY DST OR NOT? **
}
// Make call to API using modified time range
...
我怎么能去这样做?谢谢。
然而,谨防这些问题。 https://bugs.php.net/bug.php?id=40743 https://bugs.php.net/bug.php?id=49914 https://bugs.php.net/bug.php? id = 51051 https://bugs.php.net/bug.php?id=51557 https://bugs.php.net/bug.php?id=52480 https://bugs.php.net/ bug.php ID = 54340 https://bugs.php.net/bug.php?id=54655 https://bugs.php.net/bug.php?id=55253 的https://错误。 php.net/bug.php?id=60873 https://bugs.php.net/bug.php?id=60960 https://bugs.php.net/bug.php?id=61022 https: //bugs.php.net/bug.php?id=61311 https://bugs.php.net/bug.php?id=61530 https://bugs.php.net/bug.php?id= 61955 – taiganaut 2012-05-17 00:42:09
^我的上帝......... – 2013-04-29 11:33:34