PHP timezone_offset_get() Function
The PHP timezone_offset_get() function returns the offset to GMT for the date/time specified by datetime parameter. The GMT offset is calculated with the timezone information contained in the DateTimeZone object being used. This function is an alias of DateTimeZone::getOffset() method.
Syntax
//Object-oriented style public DateTimeZone::getOffset(datetime) //Procedural style timezone_offset_get(object, datetime)
Parameters
object |
Required. For procedural style only: A DateTimeZone object returned by timezone_open(). |
datetime |
Required. Specify the DateTime that contains the date/time to compute the offset from. |
Return Value
Returns time zone offset in seconds.
Example: using both styles
The example below shows the usage of timezone_offset_get() function.
<?php //creating a DateTimeZone and DateTime object $tz1 = timezone_open("Europe/London"); $date1 = date_create("10-May-2015", $tz1); //offset to GMT using Object-oriented style echo "The offset to GMT: ".$tz1->getOffset($date1)."\n"; //creating a DateTimeZone and DateTime object $tz2 = timezone_open("America/Chicago"); $date2 = date_create("10-May-2015", $tz2); //offset to GMT using Procedural style echo "The offset to GMT: " .timezone_offset_get($tz2, $date2)."\n"; ?>
The output of the above code will be:
The offset to GMT: 3600 The offset to GMT: -18000
❮ PHP Date and Time Reference