Php/docs/datetimezone.construct
来自菜鸟教程
DateTimeZone::__construct
timezone_open
(PHP 5 >= 5.2.0, PHP 7)
DateTimeZone::__construct -- timezone_open — 创建新的DateTimeZone对象
说明
面向对象风格
public DateTimeZone::__construct
( string $timezone
)
过程化风格
timezone_open
( string $timezone
) : DateTimeZone
创建新的DateTimeZone对象.
范例
Example #1 Catching errors when instantiating DateTimeZone
<?php// Error handling by catching exceptions$timezones = array('Europe/London', 'Mars/Phobos', 'Jupiter/Europa');foreach ($timezones as $tz) { try { $mars = new DateTimeZone($tz); } catch(Exception $e) { echo $e->getMessage() . '<br />'; }}?>
以上例程会输出:
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos) DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)