简体   繁体   English

使用PHP将历史时间/日期转换为GMT / UTC

[英]Convert historical time/date into GMT/UTC using PHP

In a PHP script/web application, I need to take any historical time and date and convert it into GMT or UTC. 在PHP脚本/ Web应用程序中,我需要获取任何历史时间和日期并将其转换为GMT或UTC。 I would know the latitude and longitude co-ordinates associated with each time and date, so perhaps I could derive the time zones from that somehow. 我会知道与每个时间和日期相关的纬度和经度坐标,因此也许我可以从中得出时区。

I'm vaguely aware of the Olson or 'tz' database but I'm not sure how far that is available for programmatic interrogation, or how far its incorporation into PHP5 can answer my task. 我隐约意识到Olson或'tz'数据库,但是我不确定该用于编程询问的范围,或者将其合并到PHP5中可以满足我的任务的范围。

As I understand it, this tz database is only really accurate for data after 1970, and that it makes approximations for earlier dates. 据我了解,这个tz数据库仅对1970年以后的数据真正准确,并且它是对较早日期的近似值。 If methods are likely to be error-prone for times before 1970 then perhaps at least I can flag such a case as a dubious result. 如果方法在1970年之前的时间很容易出错,那么至少我可以将这种情况标记为可疑结果。

First, use one of the methods listed here to get the TZ Database identifier for the lat/lon provided. 首先,使用此处列出的方法之一获取所提供经纬度的TZ数据库标识符。

Then, if the date is covered by the TZDB, you can just use the built-in PHP methods for conversion. 然后,如果TZDB涵盖了日期,则可以仅使用内置的PHP方法进行转换。 If those fail, then the you have two options: 如果失败,则您有两个选择:

  • You can use the Local Mean Time (LMT) value for that time zone from the TZDB, for entries that have them. 您可以使用TZDB中该时区的本地平均时间(LMT)值来输入包含它们的条目。

  • You can calculate the local solar time for the exact position, using the longitude. 您可以使用经度来计算确切位置的当地太阳时间。

Either option will be making grand assumptions about how local time was actually kept in that location at the given time. 两种选择都将对本地时间在给定时间实际上是如何保留在该位置进行大胆的假设。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM