Figure out time by latitude/longitude?

前端 未结 5 467
别跟我提以往
别跟我提以往 2020-12-10 00:13

Here\'s the deal. I have a latitude/longitude set of a location. I need to figure out what the current time is in that location. Here\'s how I was getting it before:

5条回答
  •  有刺的猬
    2020-12-10 00:45

    Unfortunately timezones (and time in general) is never as simple as you would like.

    For a simple approximation you can follow jer's suggestion. Longitude ranges from -180 to 180 degrees, there are 24 hours in a day, so you get 15 degrees of longitude per time zone. Center those time zones on 0 degrees longitude so UTC extends from -7.5 to 7.5, UTC+1 is from 7.5 to 22.5, UTC-1 is from -7.5 to -22.5, and so on. You would then have a very simplistic, and wrong, model of how we use time zones.

    Take a look at this map of time zones.

    • Time zones are not well ordered; regions in UTC-1 are adjacent to regions in UTC-3.
    • UTC-9.5, UTC-4.5, UTC+3.5, UTC+5.75, and UTC+13 are all valid time zones and actively in use.

    Once you get that sorted out then you can start to consider daylight savings time.

提交回复
热议问题