DateTimeZone
PHP Manual

DateTimeZone::__construct

timezone_open

(PHP 5 >= 5.2.0)

DateTimeZone::__construct -- timezone_openCreates new DateTimeZone object

Descrizione

Stile orientato agli oggetti

public DateTimeZone::__construct ( string $timezone )

Stile procedurale

DateTimeZone timezone_open ( string $timezone )

Creates new DateTimeZone object.

Elenco dei parametri

timezone

One of the supported timezone names.

Valori restituiti

Returns DateTimeZone on success. Stile procedurale restituisce FALSE in caso di fallimento.

Errori/Eccezioni

This method throws Exception if the timezone supplied is not recognised as a valid timezone.

Esempi

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 />';
    }
}
?>

Il precedente esempio visualizzerĂ :

DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos)
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)


DateTimeZone
PHP Manual