给定位置,在PHP中获取时区

时间:2016-02-12 15:51:49

标签: php date time timezone

我有一份地点清单。以下是示例位置:

Los Angeles, California
London, United Kingdom
New York, New York
Calgary, Alberta
Toronto, Ontario
Sydney, Australia
Phoenix, Arizona
Chicago, Illinois
Las Vegas, Nevada
Miami, Florida
Mexico City, Mexico
Houston, Texas
San Diego, California
Manchester, United Kingdom
San Antonio, Texas
Atlanta, Georgia
Dallas, Texas
Brisbane, Queensland, Australia
Montreal, Quebec
Orlando, Florida
Edmonton, Alberta
Manila, Philippines
Paris, France
Melbourne, Victoria, Australia
Nashville, Tennessee
Minneapolis, Minnesota
Perth, Western Australia
Brooklyn, New York
Columbus, Ohio
Seattle, Washington

我需要的是最接近/最匹配的PHP timezone

我目前正在使用一组正则表达式:

  $location_pregs = array(
    "'.*(California|Nevada)'si" => "America/Los_Angeles",
    "'.*United Kingdom'si" => "Europe/London",
    "'.*New York'si" => "America/New_York",
    "'.*Alberta'si" => "America/Edmonton",
    "'.*Ontario'si" => "America/Toronto",
    "'Sydney, Australia'si" => "Australia/Sydney",
    "'.*Arizona'si" => "America/Phoenix",
    "'.*Illinois'si" => "America/Chicago",
    "'.*Mexico'si" => "America/Mexico_City",
    "'(El Paso, Texas|.*Colorado)'si" => "America/Denver"
  );
  function getTimezoneAt ($location) {
    global $location_pregs;
    foreach ($location_pregs as $pn => $pc) {
      if (preg_match($pn, $location)) {
        return $pc;
      }
    }
    return false;
  }

上面的代码目前涵盖了我需要查找的27.157%的位置(考虑到受欢迎程度)。我想用最小的努力将其达到80%。我在某些地方遇到了麻烦:

  • 佛罗里达州迈阿密。据我所知,最接近的相关时区是'America / New_York'。但我怎么能确定?

  • 德克萨斯州休斯顿。据我所知,这应该是'America / Denver'。但同样,我怎么能快速判断这是否正确?

我需要的是PHP时区的地图及其覆盖的地理区域,以便我可以快速映射剩余的位置值。我通常知道某个区域的时区,但我不知道要选择哪个PHP时区。

0 个答案:

没有答案