简体   繁体   中英

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. 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.

As I understand it, this tz database is only really accurate for data after 1970, and that it makes approximations for earlier dates. 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.

First, use one of the methods listed here to get the TZ Database identifier for the lat/lon provided.

Then, if the date is covered by the TZDB, you can just use the built-in PHP methods for conversion. 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.

  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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