PHP Velho Oeste 2024

DateTimeZone::getName

timezone_name_get

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

DateTimeZone::getName -- timezone_name_getReturns the name of the timezone

Description

Object-oriented style

public DateTimeZone::getName(): string

Procedural style

Returns the name of the timezone.

Parameters

object

The DateTimeZone for which to get a name.

Return Values

Depending on zone type, UTC offset (type 1), timezone abbreviation (type 2), and timezone identifiers as published in the IANA timezone database (type 3), the descriptor string to create a new DateTimeZone object with the same offset and/or rules. For example 02:00, CEST, or one of the timezone names in the list of timezones.

add a note add a note

User Contributed Notes 1 note

up
0
man dot of dot grief at gmail dot com (Evgenii Kletsov)
2 years ago
If you construct DateTimeZone from locale name, like "Europe/Moscow", getName() returns named timezone from list.

<?php
$tz
= new \DateTimeZone('Europe/Moscow');
echo
$tz->getName(); // Europe/Moscow
?>

But if you use offset string, like "+0300", getName() returns new offset string instead of name.

<?php
$tz
= new \DateTimeZone('+0300');
echo
$tz->getName(); // +03:00
?>

It makes sense, but it's not obvious and not documented there.
To Top