php8.5
Home/ Manual/ intl / dateformatter/ IntlDateFormatter::getTimeZone

IntlDateFormatter::getTimeZone

PHP function Edit on GitHub ✎

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL intl >= 3.0.0)

Get formatterʼs timezone

Description

Oop

IntlDateFormatter::getTimeZone(): IntlTimeZone|false

Procedural

datefmt_get_timezone(IntlDateFormatter $formatter): IntlTimeZone|false

Returns an IntlTimeZone object representing the timezone that will be used by this object to format dates and times. When formatting IntlCalendar and DateTime objects with this IntlDateFormatter, the timezone used will be the one returned by this method, not the one associated with the objects being formatted.

Parameters Parameters

Return Values

The associated IntlTimeZone objectFalseforfailure.

Examples

IntlDateFormatter::getTimeZone() examples

php
<?php

$madrid = IntlDateFormatter::create(NULL, NULL, NULL, 'Europe/Madrid');
$lisbon = IntlDateFormatter::create(NULL, NULL, NULL, 'Europe/Lisbon');

var_dump($madrid->getTimezone());
echo $madrid->getTimezone()->getDisplayName(
        false, IntlTimeZone::DISPLAY_GENERIC_LOCATION, "en_US"), "\n";
echo $lisbon->getTimeZone()->getId(), "\n";
//The id can also be retrieved with ->getTimezoneId()
echo $lisbon->getTimeZoneId(), "\n";

The above example will output:

output
object(IntlTimeZone)#4 (4) {
  ["valid"]=>
  bool(true)
  ["id"]=>
  string(13) "Europe/Madrid"
  ["rawOffset"]=>
  int(3600000)
  ["currentOffset"]=>
  int(7200000)
}
Spain Time
Europe/Lisbon
Europe/Lisbon

See Also

Source: reference/intl/dateformatter/gettimezone.xml · from the official PHP manual (php/doc-en)