0

I have a list/array of timezones and I want to find the nearest timezone to a specific timezone ( where my customer is )

$timezone = ['Pacific/Honolulu', 'America/Anchorage', 'America/Santa_Isabel', 'America/Los_Angeles'];

And let's say my customer is in Europe/Paris Timezone.

How can I find the nearest timezone from the $timezone array?

Looking for a solution in PHP.

dvl333
  • 183
  • 1
  • 12
  • Hi. The nearest timezone in the list? for Europe/Paris would it be Europe/Oslo or Europe/Podgorica? Or other ? – Monnomcjo Aug 23 '22 at 13:49
  • You'll need to define "nearest" more clearly. Perhaps "the time zone which, at the time the script runs, has the closest UTC offset"? Do you care what happens if there's a tie? – IMSoP Aug 23 '22 at 13:56
  • What I mean by nearest is by the difference in the number of hours or minutes, the lesser the difference is the closest one – dvl333 Aug 23 '22 at 14:00
  • But many zones have the same time offset. i think you should forget timezones, and just use time offsets (but in case you need to plan in advance, e.g. with summer time, but in this case your method is also not working). – Giacomo Catenazzi Aug 23 '22 at 15:16
  • Does this answer your question? [How to get a time zone from a location using latitude and longitude coordinates?](https://stackoverflow.com/questions/16086962/how-to-get-a-time-zone-from-a-location-using-latitude-and-longitude-coordinates) – Markus Zeller Aug 23 '22 at 18:43

0 Answers0