略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: DateTimeZone::getName

2024-05-04

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对象。

返回值

时区名称列表之一。

add a noteadd a note

User Contributed Notes 1 note

up
-1
man dot of dot grief at gmail dot com (Evgenii Kletsov)
8 months 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.

官方地址:https://www.php.net/manual/en/datetimezone.getname.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3