DateTime::getTimezone

(PHP 5 >= 5.2.0, PHP 7)
Return time zone relative to given DateTime
public DateTimeZone DateTime::getTimezone ( void )

Object oriented style

public DateTimeZone DateTimeImmutable::getTimezone ( void )
public DateTimeZone DateTimeInterface::getTimezone ( void )

Procedural style

Return time zone relative to given DateTime.

Parameters:
object

Procedural style only: A DateTime object returned by date_create()

Returns:

Returns a DateTimeZone object on success or FALSE on failure.

Examples:
DateTime::getTimezone() example

Object oriented style

<?php
$date = new DateTime(null, new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
?>

Procedural style

<?php
$date = date_create(null, timezone_open('Europe/London'));
$tz = date_timezone_get($date);
echo timezone_name_get($tz);
?>

The above examples will output:

Europe/London
See also:

DateTime::setTimezone() -

doc_php
2016-02-24 15:56:24
Comments
Leave a Comment

Please login to continue.