(PHP 5 >= 5.2.0, PHP 7)

DateTimeZone::__construct -- timezone_openCreates new DateTimeZone object


Stile orientato agli oggetti

public DateTimeZone::__construct ( string $timezone )

Stile procedurale

timezone_open ( string $timezone ) : DateTimeZone|false

Creates new DateTimeZone object.

Elenco dei parametri


One of the supported timezone names or an offset value (+0200).

Valori restituiti

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


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

Log delle modifiche

Versione Descrizione
5.5.10 The timezone parameter accepts offset values.


Example #1 Catching errors when instantiating DateTimeZone

// 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) {
$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)

add a note add a note

User Contributed Notes

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