PHP Portal » PHP Handbuch » DateTimeZone::__construct

Werbung

DateTimeZone::__construct


(PHP 5 >= 5.2.0)

DateTimeZone::__constructCreates new DateTimeZone object

Beschreibung

public DateTimeZone::__construct ( string $timezone )

Creates new DateTimeZone object.

Parameter-Liste

timezone

One of timezones.

Rückgabewerte

Returns DateTimeZone on success.

Fehler/Exceptions

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

Beispiele

PHP Code
1
2
3
4
5
6
7
8
9
10
// 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)