PHP Velho Oeste 2024

DateTimeZone::getName

timezone_name_get

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

DateTimeZone::getName -- timezone_name_get返回时区名称

说明

面向对象风格

public DateTimeZone::getName(): string

过程化风格

返回时区名称。

参数

object

要获得名称的 DateTimeZone

返回值

根据区域类型、UTC 时差(类型 1)、时区缩写(类型 2)和 IANA 时区数据库发布的时区标识符(类型 3),描述符字符串使用相同时差和/或规则创建新的 DateTimeZone。例如:02:00CEST 或者 时区列表中的其中一个时区名称。

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