ConFoo: Call for paper is now Open

DateTimeZone::__construct

timezone_open

(PHP 5 >= 5.2.0)

DateTimeZone::__construct -- timezone_openCreates new DateTimeZone object

说明

面向对象风格

public DateTimeZone::__construct ( string $timezone )

过程化风格

DateTimeZone timezone_open ( string $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)

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top