Reputation: 2538
I have a list of timezones name in by database:
I need to get the UTC Offset in PHP. For example for America/Anchorage I need to have UTC-9
and so on.
Upvotes: 2
Views: 1081
Reputation: 406
you can use
$dateTimeZoneJapan = new DateTimeZone("America/Adak");
$timeOffset = $dateTimeZoneJapan->getOffset( new DateTime("now", new DateTimeZone("UTC")) );
if ($timeOffset < 0){ //if time offset is negative
echo "-".gmdate("H", -$timeOffset);
}else{
echo gmdate("H", $timeOffset); //H will give number of hours.
}
this will give you time zone offset in seconds on success or FALSE on failure.
Upvotes: 1