(PHP 5 >= 5.2.0, PHP 7)
Creates new DateTimeZone object
DateTimeZone timezone_open ( string $timezone )
Object oriented style
public DateTimeZone::__construct ( string
$timezone
)Procedural style
Creates new DateTimeZone object.
Parameters:
timezone
One of the supported timezone names.
Returns:
Returns DateTimeZone on success. Procedural style returns FALSE
on failure.
Exception:
This method throws Exception if the timezone supplied is not recognised as a valid timezone.
Examples:
Catching errors when instantiating DateTimeZone
1 2 3 4 5 6 7 8 9 10 11 12 | <?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 />' ; } } ?> |
The above example will output:
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos) DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)
Please login to continue.