DateTimeZone
PHP 手册

DateTimeZone::__construct

(PHP 5 >= 5.2.0)

DateTimeZone::__constructCreates new DateTimeZone object

说明

DateTimeZone::__construct ( string $timezone )

Creates new DateTimeZone object.

参数

timezone

One of timezones.

返回值

Returns DateTimeZone on success.

错误/异常

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)


DateTimeZone
PHP 手册