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)
You haven't thought this through.
Many US states have multiple time zones. For example, South Dakota has both Mountain and Central time zones.
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.
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',
);
Related
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 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;
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.
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.
I am storing the user viewdatetime column from my server time (India), and I want to convert this time depending on the users country. I can get the user country and some details by this steps
Getting visitors country from their IP
Can you give me some suggestion
The best way to do it would be using moment.js library (http://momentjs.com/) and benefit from its Multiple Locale Support.
You should really handle this stuff on client-side (thus JavaScript) instead of server-side (PHP). I hope this answer will be useful.
I guess your viewdatetime column is a DATETIME datatype. If that's true, then the CONVERT_TZ() function will prove helpful. For example, if your user's time zone is Australia/Canberra you can do this:
SELECT CONVERT_TZ(viewdatetime, 'Asia/Dili', 'Australia/Canberra');
But, of course you have to use a public API that guesses the user's time zone from the ip address. Knowing the country isn't enough.
India has a single national time zone. Australia has four. USA has a chaotic set of local rules about daylight savings time, meaning there are roughly twelve distinct time zones. Canada has six zones.
Best practice in this area is to allow each registered user to specify her own time zone preference, and show unregistered users dates and times in your own time zone.
I need to add the ability to change timezones for North America only. There are a total of six timezones, including Hawaii and Alaska.
I am on the eastern part of the USA, so my timezone is Eastern. When choosing a timezone for my location, I can choose New York, Chicago and a few others. I'm not sure why there are so many different timezones that all resolve to the same offset; unless because of DST.
All I'm basically looking for are these six zones:
EST
CST
MST
PST
AKST
HST
Can someone tell me why there are so many different timezones to choose from that resolve to the same offset?
The list of PHP timezones is pulled from the PECL timezone database. The PECL timezone database comes from the "Olson" database, which is maintained by the IANA organization.
On the IANA website, they state the following about their upkeep of the timezone database:
The Time Zone Database (often called tz or zoneinfo) contains code and
data that represent the history of local time for many representative
locations around the globe. It is updated periodically to reflect
changes made by political bodies to time zone boundaries, UTC offsets,
and daylight-saving rules. Its management procedure is documented in
BCP 175: Procedures for Maintaining the Time Zone Database.
The topic of timezones is further complicated by the fact that not all states use daylight savings (Arizona, Hawaii, Puerto Rico, for example do not use daylight savings).
So, what one could conclude from this is that a timezone for a particular City is based on its zone boundaries, its daylight savings time rules, and other political factors. Thus, just because some city happens to be physically in the west does not mean it is guaranteed to be PST, for example.
Furthermore, by manually setting a western region to PST is technically less maintainable than it would be to set its actual country/city timezone identifier, so that way, should their offset change in the future, your application would continue to set the correct time.
We have been using IPLEGENCE Database pro to get user timezone based on IP address. Here I have a few unusal time zone off sets. Which are listed below
EST+1
PST-2
PST-1
GMT+12.75
I am not sure what exactly above listed off sets.
Could some one please help me in converting the above time zones to UTC.
Thanks for your time.
Here is a list of time zones. EST is almost always (excepting for those DST overlaps) GMT-5. And GMT is either on UTC, or an hour off (again, DST).
EST+1 = GMT-4
PST-2 = GMT-10
PST-1 = GMT-9
The best you can probably do, if you want to convert it to UTC, is to use the DateTime object.
That is rather a strange way to denote time zones. My guess is that GMT+12:45 refers to the Chatham Islands. Not sure about the others, they could be anywhere.
IMHO, there are a few problems with this type of data:
Time zones are not fixed offsets. When the database refers to EST, they probably mean "US Eastern Time". But that could refer to -5 hours offset for Eastern Standard Time (EST), or -4 hours for Eastern Daylight Time (EDT). By calling it "EST" in the data, they are fixing it to -5, when in fact it might be -4. See "Time Zone != Offset" in the timezone tag wiki.
Time zone abbreviations can be ambiguous. For example, how do I know that "EST" really refers to USA's Eastern Standard Time (-5)? It might refer to Australia's Eastern Standard Time (+10). There is a list here, and you can see there are lots of time zones with the same abbreviation.
IP Geolocation is a "best guess", and does not have the kind of accuracy needed to determine time zone. The time zone in these databases may match the listed coordinates, but you have very little guarantee that the user is actually at those coordinates. It might be giving you the location of a proxy server or network router. This is especially true on corporate networks, where (in some cases) you have an IP in a corporate office in another city and all Internet traffic filters through that IP. You're going to get the timezone of that corporate office - not the time zone of the user. You can read more about IP Geolocation Accuracy here and here.
If you know the coordinates of the user by some other means, such as from GPS data on a cell phone, then you can use one of the several different techniques described here.
More I think about this, more it gets difficult
The idea is to have a form where each person chooses his timezone and a time range and days of week available
ex.
Timezone
USA eastern
10pm-11pm sunday(checked) thursday (checked)
Now, someone searching the db from france will set his timezone to be 6hours later
any simple way to do this in php?
every use could be in a different timezone. so hours and maybe day of week will be different.
My personal recommendation would be to do all the storing and processing in the same time-zone (for example, GMT). Then, based on the user's settings simply display the times differently when outputting them to him by adjusting them by the necessary amount.