The date_offset_get() function is an inbuilt function in PHP which is used to returns the timezone offset. This function returns the timezone offset in seconds from UTC (Universal Time Coordinated) on success or FALSE on failure.
Syntax:
- Procedural Style:
int date_offset_get( $object )
- Object Oriented Style:
int DateTime::getOffset( void ) int DateTimeImmutable::getOffset( void ) int DateTimeInterface::getOffset( void )
Parameters: This function accepts single parameter $object which is mandatory in procedural style. The DateTime object returned by date_create() function. But in case of object oriented style no parameter required.
Return Value: This function returns the timezone offset in seconds from UTC(Universal Time Coordinated) on success or FALSE on failure.
Below programs illustrate the date_offset_get() function in PHP:
Program 1:
<?php $date1 = date_create('2018-09-12', timezone_open('Asia/Kolkata')); $date2 = date_create('20018-09-18', timezone_open('Asia/Singapore')); echo date_offset_get($date1) . "\n"; echo date_offset_get($date2) . "\n"; ?> |
19800 28800
Program 2:
<?php $date1 = new DateTime('2018-09-12', new DateTimeZone('Asia/Kolkata')); $date2 = new DateTimeImmutable('2018-09-18', new DateTimeZone('Asia/Singapore')); echo $date1->getOffset() . "\n"; echo $date2->getOffset() . "\n"; ?> |
19800 28800
Related Articles:
Reference: http://php.net/manual/en/datetime.getoffset.php
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

