Get the official American time zone in PHP?

后端 未结 2 1415
天命终不由人
天命终不由人 2020-12-07 06:38

I have account stored in my database and I have each account state on file, from there I want to link each account to a timezone based on the account state.

so if th

相关标签:
2条回答
  • 2020-12-07 06:58

    It's always best to go to the source: http://www.php.net/manual/en/timezones.america.php

    For all timezones: http://www.php.net/manual/en/timezones.php

    If you read down the page on the first link, someone was nice enough to make an array if you need the abbreviations:

    $aTimeZones = array(
      'America/Puerto_Rico'=>'AST',
      'America/New_York'=>'EDT',
      'America/Chicago'=>'CDT',
      'America/Boise'=>'MDT',
      'America/Phoenix'=>'MST',
      'America/Los_Angeles'=>'PDT',
      'America/Juneau'=>'AKDT',
      'Pacific/Honolulu'=>'HST',
      'Pacific/Guam'=>'ChST',
      'Pacific/Samoa'=>'SST',
      'Pacific/Wake'=>'WAKT',
    ); 
    
    0 讨论(0)
  • 2020-12-07 07:11

    You haven't thought this through.

    Many US states have multiple time zones. For example, South Dakota has both Mountain and Central time zones.

    South Dakota Time Zone Map

    If you desire to resolve a location to a time zone, you will need a much more granular location. Ideally, a latitude and longitude. If you don't have one, you can approximate the centroid lat/lon of a zip code, and then use that against any of many various services or databases that will resolve that to a time zone. But be very careful, not all zip codes represent physical locations, and zip codes change frequently.

    0 讨论(0)
提交回复
热议问题