skip to Main Content

I want to find the timezone with the country and region using

geoip_time_zone_by_country_and_region()

but seems it needs geoip ext to be installed which is not supported anymore
and seems geoip2 just works with IP but I want to get the timezone by country and region(state) name
is there any solution?
I’m using Laravel 9 and PHP 8.1

2

Answers


  1. 2 choices

    Get free versions of maxmind geoip (Geolite DB) and use them . Cumbersome for just the zone

    Use javascript https://www.geeksforgeeks.org/how-to-set-timezone-offset-using-javascript/ ..offset example

    Or if you want the actual zone text:

    var justforRefTz ; justforRefTz = Intl.DateTimeFormat().resolvedOptions().timeZone;
    
    Login or Signup to reply.
  2. The geoip_time_zone_by_country_and_region function uses hardcoded data from this file, which is deprecated and hasn’t had any time zone data updated since 2013. You should definitely not use it any more.

    Additionally, that function by its definition alone is impossible to accurately implement, as there are many regions that use different time zones in different places within the region. Just in the USA alone, there are 16 states that have more than one time zone.

    As an example, the US state of South Dakota is split almost down the middle between the Mountain and Central time zones.

    Time Zones in South Daktoa

    geoip_time_zone_by_country_and_region("US", "SD") is hardcoded to return "America/Chicago" – which is the IANA time zone identifier for US Central Time – which applies in the eastern half of South Daktoa only. The western half should use "America/Denver" instead.

    Any approach to resolving a time zone needs to take much more than just country and region into account. A more accurate approach would be to use latitude and longitude coordinates, which could be resolved from an address (or at least a country, region, and city) via a number of different techniques.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search