DateTimeZone::__construct
timezone_open
(PHP 5 >= 5.2.0)
DateTimeZone::__construct -- timezone_open — Creates new DateTimeZone object
Beschreibung
Objektorientierter Stil
public DateTimeZone::__construct
( string
$timezone
)Prozeduraler Stil
Creates new DateTimeZone object.
Rückgabewerte
Returns DateTimeZone on success.
Prozeduraler Stil Im Fehlerfall wird FALSE zurückgegeben.
Fehler/Exceptions
This method throws Exception if the timezone supplied is not recognised as a valid timezone.
Beispiele
Beispiel #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 />';
}
}
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos) DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)