Php convert timezone to offset
How would I go about converting a timezone name ("Asia/Dubai", "Europe/Andorra", etc) to a GMT offset in hours (or even seconds, since I can convert it from there). Show Most people ask for the reverse, but I need to get a timezone offset from the timezone name provided by GeoNames. asked Jan 18, 2011 at 19:49
3 you can use the following
answered Jan 18, 2011 at 19:58
Cecil ZorgCecil Zorg 1,45913 silver badges15 bronze badges 3 Another option would be to use the available
answered Jan 18, 2011 at 22:33
salathesalathe 50.4k11 gold badges103 silver badges130 bronze badges 1 I like using PHP Carbon:
answered Jun 5, 2015 at 2:29
mopo922mopo922 6,2063 gold badges27 silver badges31 bronze badges ❮ PHP Date/Time Reference ExampleReturn the timezone offset from GMT: $tz=timezone_open("Asia/Taipei"); Try it Yourself » Definition and UsageThe timezone_offset_get() returns the timezone offset from GMT. Syntaxtimezone_offset_get(object, datetime) Parameter Values
Technical Details
❮ PHP Date/Time Reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
How to get offset from timezone in PHP?The timezone_offset_get() function is an inbuilt function in PHP which is used to return the timezone offset from GMT. The date time object and the date-time are sent as a parameter to the timezone_offset_get() function and return the timezone offset in seconds on success or False on failure.
How do you convert timezone to offset?$tz->getOffset(new \DateTime()); Example. Note that the offset produced in the example will vary between 0 and 3600 depending on what date and time you are viewing it. As you are storing the users timezone you never have to face the futility of trying to convert an offset to the correct timezone.
How to get local timezone in PHP?The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.
|