user3351236
user3351236

Reputation: 2538

How do I get the UTC Offset in PHP

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

Answers (1)

Deepak Singh
Deepak Singh

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

Related Questions