DateTimeInterface::getTimezone

DateTimeImmutable::getTimezone

DateTime::getTimezone

date_timezone_get

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

DateTimeInterface::getTimezone -- DateTimeImmutable::getTimezone -- DateTime::getTimezone -- date_timezone_getReturn time zone relative to given DateTime

Description

Object-oriented style

public DateTimeInterface::getTimezone(): DateTimeZone|false
public DateTimeImmutable::getTimezone(): DateTimeZone|false
public DateTime::getTimezone(): DateTimeZone|false

Procedural style

Return time zone relative to given DateTime.

Parameters

object

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

Return Values

Returns a DateTimeZone object on success or false on failure.

Examples

Example #1 DateTime::getTimezone() example

Object-oriented style

<?php
$date
= new DateTimeImmutable(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

add a note add a note

User Contributed Notes 1 note

up
0
Daniele Mams
10 years ago
the getTimestamp() function and the format("U") function for get the timestamp from a DateTime object, first convert the object in UTC TimeZone, and then give the timestamp int.
To Top