DateTimeZone::__construct
timezone_open
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DateTimeZone::__construct -- timezone_open — 创建新的DateTimeZone对象
说明
面向对象风格
public DateTimeZone::__construct(string
$timezone
)过程化风格
创建新的DateTimeZone对象.
返回值
成功时返回 DateTimeZone对象.
过程化风格在失败时返回 false
。
错误/异常
如果提供的时区无效,此方法将抛出 Exception异常.
范例
示例 #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)

User Contributed Notes
There are no user contributed notes for this page.
备份地址:http://www.lvesu.com/blog/php/datetimezone.construct.php