📜  PHP | timezone_open()函数

📅  最后修改于: 2022-05-13 01:56:41.382000             🧑  作者: Mango

PHP | timezone_open()函数

timezone_open()函数是PHP中的一个内置函数,用于创建新的 DateTimeZone 对象。 timezone_open()函数接受时区作为参数,成功时返回 DateTimeZone 对象,失败时返回 False。

句法:

timezone_open( $timezone )

参数:此函数接受单个参数$timezone是强制性的。它指定要创建的新 DateTimeZone 对象的时区。

返回值:成功时返回 DateTimeZone 对象,失败时返回 False。

例外:作为参数传递的时区必须是PHP支持的时区,否则可能会导致错误的结果。

下面的程序说明了PHP中的 timezone_open()函数:

方案一:


输出:
The new DateTimeZone object created is America/Chicago

方案二:

");
}
?>
输出:
The new DateTimeZone object created is Europe/LondonThe new DateTimeZone object created is Asia/Kolkata

注意: timezone_open()函数会发出警告,因为传递的时区不是支持/有效的时区。

参考: 函数 : PHP 。 PHP