<?php
/* - - - - - - - - - - - - - - - - - - -
Object oriented style I
- - - - - - - - - - - - - - - - - - - */
int public DateTime::getOffset ( )
?>
<?php
/* - - - - - - - - - - - - - - - - - - - -
Object oriented style II
- - - - - - - - - - - - - - - - - - - - */
int public DateTimeImmutable::getOffset ( )
?>
<?php
/* - - - - - - - - - - - - - - - - - - - -
Object oriented style III
- - - - - - - - - - - - - - - - - - - - */
int public DateTimeInterface::getOffset ( )
?>
<?php
/* - - - - - - - - - - - - - - - - -
Procedural style
- - - - - - - - - - - - - - - - - */
int date_offset_get ( DateTimeInterface $object )
where,
$object = DateTimeZone object representing the desired time zone
?>
<?php
$tz01 = 'America/Sao_Paulo';
$asp01 = new DateTime('now', new DateTimeZone($tz01));
echo 'offset = ' . $asp01->getOffset() . 's = ' . bcdiv($asp01->getOffset(), 3600). 'h<br><br>for ' . $tz01 . ' in relation to UTC.<br>';
?>
<?php
$tz02 = 'UTC';
$asp02 = new DateTimeImmutable('now', new DateTimeZone($tz02));
echo 'offset = ' . $asp02->getOffset() . 's = ' . bcdiv($asp02->getOffset(), 3600). 'h<br><br>for ' . $tz02 . ' in relation to UTC.<br>';
?>
<?php
// With each new run, a new offset
// will be displayed for a new time zone
$arrtz03 = timezone_identifiers_list();
$cnt03 = (count($arrtz03) - 1);
$rd03 = mt_rand(0, $cnt03);
$tz03 = $arrtz03[$rd03];
date_default_timezone_set($tz03);
$asp03 = date_create ("now", timezone_open($tz03));
$ofs03 = date_offset_get($asp03);
echo 'offset = ' . $ofs03 . 's = ' . bcdiv($ofs03, 3600). 'h<br><br>for ' . $tz03 . ' in relation to UTC.<br>';
?>