DateTimeZone::__construct

timezone_open

(PHP 5 >= 5.2.0, PHP 7)

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.

Приклади

Приклад #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