PHP - 为没有时区名称的区域设置默认时区偏移量(海域)
PHP - set default timezone offset for areas without timezone name (sea locations)
我正在编写 PHP 使用时区的应用程序。对于陆基 GPS,我使用
date_default_timezone_set();
使用正确的名称,如 Europe/Dublin
。但是,如果 GPS 位置不是陆地而是在海上,则没有时区名称,但时间与 UTC 有偏差。计算是大约。经度 15 度 1 小时。我已经手动计算了 UTC 偏移量,但无法将其设置为 PHP。我正在使用 date
方法从 unix 时间戳打印人类可读的日期。
我发现有像 Etc/GMT+10
这样的其他时区名称 (https://www.php.net/manual/en/timezones.others.php),但是 PHP 文档指出:
Warning Please do not use any of the timezones listed here (besides UTC), they
only exist for backward compatible reasons, and may expose erroneous
behavior.
使用基于 Etc
的补偿是否安全?或者还有其他安全的解决方案吗?我还没有找到任何。在 date_default_timezone_set()
评论某人 "uses" 这个: https://www.php.net/manual/en/function.date-default-timezone-set.php#96551 但它看起来很丑。
我正在使用 PHP 7.1.
PHP 中的时区源自 IANA tz database。
特别是 Etc/GMT+10
等区域源自 tz 数据中的 etcetera
文件,which says(强调我的):
... These days, the
tz files cover almost all the inhabited world, and the only practical
need now for the entries that are not on UTC are for ships at sea
that cannot use POSIX TZ settings.
因此,您确实可以并且应该将它们用于您描述的目的。
请记住,它们仅存在于从 Etc/GMT-14
到 Etc/GMT+12
的整小时偏移,并且区域名称中的符号与标准约定相反。换句话说 Etc/GMT+10
实际上是 UTC-10.
另一个注意事项。我的理解是,海上船舶在这些陆地附近的领海内使用陆地时区是很常见的,包括任何有效的夏令时调整。例如,一艘在美国领海内沿太平洋沿岸航行的船只应更改其时钟,以在冬季使用 PST (UTC-8),在夏季使用 PDT (UTC-7)。这是由 America/Los_Angeles
建模的,而纯纵向计算将全年使用 UTC-8 (Etc/GMT+8
)。
这一切都是灵活的,因为船长基本上可以自行决定登船时间。有关详细信息,请参阅维基百科关于 nautical time 的文章。
您可能还希望 read here about methods to use GPS coordinates to resolve an IANA time zone. Those that use the Time Zone Boundary Builder project as a data source (such as the Geo-Timezone PHP library) 受益于同时考虑航海时间和领海。
我正在编写 PHP 使用时区的应用程序。对于陆基 GPS,我使用
date_default_timezone_set();
使用正确的名称,如 Europe/Dublin
。但是,如果 GPS 位置不是陆地而是在海上,则没有时区名称,但时间与 UTC 有偏差。计算是大约。经度 15 度 1 小时。我已经手动计算了 UTC 偏移量,但无法将其设置为 PHP。我正在使用 date
方法从 unix 时间戳打印人类可读的日期。
我发现有像 Etc/GMT+10
这样的其他时区名称 (https://www.php.net/manual/en/timezones.others.php),但是 PHP 文档指出:
Warning Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons, and may expose erroneous behavior.
使用基于 Etc
的补偿是否安全?或者还有其他安全的解决方案吗?我还没有找到任何。在 date_default_timezone_set()
评论某人 "uses" 这个: https://www.php.net/manual/en/function.date-default-timezone-set.php#96551 但它看起来很丑。
我正在使用 PHP 7.1.
PHP 中的时区源自 IANA tz database。
特别是 Etc/GMT+10
等区域源自 tz 数据中的 etcetera
文件,which says(强调我的):
... These days, the tz files cover almost all the inhabited world, and the only practical need now for the entries that are not on UTC are for ships at sea that cannot use POSIX TZ settings.
因此,您确实可以并且应该将它们用于您描述的目的。
请记住,它们仅存在于从 Etc/GMT-14
到 Etc/GMT+12
的整小时偏移,并且区域名称中的符号与标准约定相反。换句话说 Etc/GMT+10
实际上是 UTC-10.
另一个注意事项。我的理解是,海上船舶在这些陆地附近的领海内使用陆地时区是很常见的,包括任何有效的夏令时调整。例如,一艘在美国领海内沿太平洋沿岸航行的船只应更改其时钟,以在冬季使用 PST (UTC-8),在夏季使用 PDT (UTC-7)。这是由 America/Los_Angeles
建模的,而纯纵向计算将全年使用 UTC-8 (Etc/GMT+8
)。
这一切都是灵活的,因为船长基本上可以自行决定登船时间。有关详细信息,请参阅维基百科关于 nautical time 的文章。
您可能还希望 read here about methods to use GPS coordinates to resolve an IANA time zone. Those that use the Time Zone Boundary Builder project as a data source (such as the Geo-Timezone PHP library) 受益于同时考虑航海时间和领海。