-2

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 the account's state is California then the timezone will be "America/Los_Angeles"

More, I want to break down the time zone that is provided at this page http://php.net/manual/en/timezones.america.php by Atlantic Eastern Central Mountain Pacific Alaska Hawaii - Aleutian

Now I will be able to sort my data based on 7 time zones and also I can have all my account linked to a timezone so I can determine their time zone.

So My question 1) How can I figure out what state is linked to what timezone. (example: California = "America/Los_Angeles")

2) Which timezone are linked to what timezone category. (example: California = Pacific)

Jaylen
  • 39,043
  • 40
  • 128
  • 221
  • 4
    Do `PHP date timezones` search in Google, you'll get the list. *Literally*. I don't know what you mean by *the* official timezone, there's seven or eight depending on which states you count, plus daylight savings, non-daylight savings. Right now the main ones are probably Eastern, Central, Mountain and Pacific. – Jared Farrish Mar 28 '13 at 06:10
  • To reiterate - what do you mean by "the main ones". If you are looking for those defined by law, you can review [15 USC §260-267](http://www.law.cornell.edu/uscode/text/15/chapter-6/subchapter-IX). [§263](http://www.law.cornell.edu/uscode/text/15/263) in particular. But this is not very helpful for computing. PHP uses the IANA/Olson timezone database, which does have abbreviations closely matching the legal names. If you want to see it visually, [look here](http://www.time.gov/images/US_time_zones.gif). – Matt Johnson-Pint Mar 28 '13 at 14:42

2 Answers2

3

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.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Thanks for that tip, I do have the zip code for every account, so where can I pass that agins to get the time zone? – Jaylen Mar 29 '13 at 06:09
  • There are lots of ways to do this, and its been [asked](http://stackoverflow.com/q/8842153/634824) [many](http://stackoverflow.com/q/2456324/634824) [times](http://stackoverflow.com/q/15304198/634824) [before](http://stackoverflow.com/q/11354490/634824). Probably the easiest way is with the Google APIs for [GeoCoding](https://developers.google.com/maps/documentation/geocoding/) and [TimeZones](https://developers.google.com/maps/documentation/timezone/) – Matt Johnson-Pint Mar 29 '13 at 13:56
  • Very Very nice. I guess my last question will be, will TimeZones class handle the daylight saving automatically? or I have to do extra calculation for that? so If I link every account with a time zone using google GeoCoding, then when i do new DateTime(some_date, new DateTimeZone(account_time_zone) ); this will automaticly handles the daylight saving? Thanks – Jaylen Mar 29 '13 at 17:23
  • That's where you will use the PHP time zone functions. For example, [see this](http://www.php.net/manual/en/function.date-timezone-set.php). – Matt Johnson-Pint Mar 29 '13 at 18:02
1

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',
); 
AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35
  • Yes I have seen that prior posting my question but that gives a list of everything, I only need the main once – Jaylen Mar 28 '13 at 13:37