php - Convert UTC offset to timezone or date -
A head scratcher for you
I am grabing geo IP data with my API and it UTC Returns Offset Off TimeSam from Including DST (Currently Reflected). For example, I live in EST (-5) and currently it is DST, so the geographic IP API return ( This is very good because DST headache disturbances but due to my surprise, it caused another headache. I load this data into PHP, which can be applied through AJAX. I would like an IP address live locally at the app. I have this set completely, but I'm crazy about how to try to find out how to set the PHP timezone to offset the match so I just have the current hour I have no uncertainty if there is a specific task which can give me current hours and minutes based on that offset, or if there is no practical way to set the timezone based offset (which DST already applied If it is in effect). I am searching and searching Google to get answers to this, but what I am doing is more specific because DST is already implemented. I feel like a function that moves (this works for my timezone and gives the right time), however for other time zones like PST, it has to return after 1 hour, although the offset is correct Is (with The timezone is again functioning with This is now the job I have. Please excuse the most suspicious code. I have included a switch / case for the specific timezone that is outside Note: Offset is always returned as such I appreciate any help or a point in the right direction. I'm not a very newbie with PHP, but offset is a new story for me Thanks! By changing it offset in seconds and making it the : Timezone_name_frame_ab () will change false on some time zone offsets. Specifically - Hawaii, in which GMT offset is -10,000 -36000 seconds. Reference: -04: 00 ) in the form of offsets
date ('H' '); More minutes
date ('I'); I can take to pass through AJAX.
-07: 00 DST).
Chile / Easter East due to which I have a feeling if I could, I would only do this for America, but I need it all over the world.
offsetToTZ ($ $) offset function) {switch (string) $ offset) {case '-04: 30': return 'America / Caracas'; break; Case '-03: 30': Return 'Canada / Newfoundland'; break; Case '+03: 30': Return 'Asia / Tehran'; break; Case '04: 30 ': Return' Asia / Kabul '; break; Cases '05: 30 ': Return' Asia / Kolkata '; break; Case '05: 45 ': Return' Asia / Kathmandu '; break; Case '+09: 30': Return 'Australia / Darwin'; break; } $ Offset = (int) str_replace (array ('0', 0, ': 00', 00, '30 ', 30,' 45 ', 45,': ',' + '),' ', $ Offset); $ Offset = $ offset * 60 * 60; $ Abbrarray = timezone_abbreviations_list (); Foreign currency ($ abbrarray $ abbr) {foreach ($ city as $ abbr) {if ($ city ['offset'] == $ offset) {return $ city ['timezone_id']; } } } return false; }
: 30 and
: 45
+ 00 00: >. code> or
-00: 00 from the GO IP API
timezone_name_frame_buffer :
& lt ;? Php $ offset = '-7: 00'; // Calculate seconds from offset list ($ hour, $ min) = explosion (':', offset offset); $ Sec = $ hours * 60 * 60 + $ min * 60; // get the timezone name from second $ tz = timezone_name_frame_ ('', $ sec, 1); // Workaround for Bug # 44780 ($ tz === false) $ tz = timezone_name_frame_ ('', $ sec, 0); // set timezone date_default_timezone_set ($ tz); Echo $ Tz ':'. Date ('r'); The third parameter of
timezone_name_from_abbr controls whether daylight saving time is adjusted or not.
Comments
Post a Comment