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:
php
php
- Procedural Style:
int date_offset_get( $object )
- Object Oriented Style:
int DateTime::getOffset( void ) int DateTimeImmutable::getOffset( void ) int DateTimeInterface::getOffset( void )
<?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";
?>
Output:
Program 2:
19800 28800
<?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";
?>
Output:
Related Articles:
Reference: https://www.php.net/manual/en/datetime.getoffset.php19800 28800