In this article, you will learn how to get the timezone offset. The timezone_offset_get()
the method in PHP returns the offset of the timezone from the GMT.
What is the syntax of the timezone_offset_get() function in PHP?
timezone_offset_get(object, datetime)
Parameter | Description |
---|---|
object | The DateTime object is returned by the timezone_open method. – Required |
datetime | Date/time to allow the function to get offset from it – Required |
Example of the timezone_offset_get() function
Example 1. In this example, we create a new timezone object using the timezone_open() method and a date/time object. We pass both of these objects to the timezone_offset_get() function to calculate the offset.
<?php
$timezone=timezone_open("Asia/Taipei");
$oslo=date_create("now",timezone_open("Europe/Oslo"));
echo timezone_offset_get($timezone,$oslo);
?>