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).
Most people ask for the reverse, but I need to get a timezone offset from the timezone name provided by GeoNames.
you can use the following
<?php
$timezone = 'Pacific/Nauru';
$time = new \DateTime('now', new DateTimeZone($timezone));
$timezoneOffset = $time->format('P');
?>
Another option would be to use the available DateTimeZone::getOffset()
method, which returns the offset in seconds for the time zone at the specified date/time.
$timezone = new DateTimeZone("Europe/Andorra");
$offset = $timezone->getOffset(new DateTime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With