How to get a time zone from a location using latitude and longitude coordinates?

后端 未结 17 1969
走了就别回头了
走了就别回头了 2020-11-21 04:38

Given the latitude and longitude of a location, how does one know what time zone is in effect in that location?

In most cases, we are looking for an IANA/Olson time z

17条回答
  •  孤城傲影
    2020-11-21 05:11

    We at Teleport just started opening up our API's and one of the usecases is also exposing TZ information for coordinates.

    For example one could request all our available TZ information for coordinates in following manner:

    curl -s https://api.teleport.org/api/locations/59.4372,24.7453/?embed=location:nearest-cities/location:nearest-city/city:timezone/tz:offsets-now | jq '._embedded."location:nearest-cities"[0]._embedded."location:nearest-city"._embedded."city:timezone"'
    

    This would return the following

    {
      "_embedded": {
        "tz:offsets-now": {
          "_links": {
            "self": {
              "href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/offsets/?date=2015-09-07T11%3A20%3A09Z"
            }
          },
          "base_offset_min": 120,
          "dst_offset_min": 60,
          "end_time": "2015-10-25T01:00:00Z",
          "short_name": "EEST",
          "total_offset_min": 180,
          "transition_time": "2015-03-29T01:00:00Z"
        }
      },
      "_links": {
        "self": {
          "href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/"
        },
        "tz:offsets": {
          "href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/offsets/{?date}",
          "templated": true
        },
        "tz:offsets-now": {
          "href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/offsets/?date=2015-09-07T11%3A20%3A09Z"
        }
      },
      "iana_name": "Europe/Tallinn"
    }
    

    For the example I used ./jq for JSON parsing.

提交回复
热议问题