©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(PHP 5 >= 5.2.0, PHP 7)
DateTimeZone::__construct -- timezone_open — Creates new DateTimeZone object
面向对象风格
$timezone
)过程化风格
$timezone
)Creates new DateTimeZone object.
timezone
One of the supported timezone names.
Returns DateTimeZone on success.
过程化风格在失败时返回 FALSE
。
This method throws Exception if the timezone supplied is not recognised as a valid timezone.
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)