DateTimeZone::__construct

timezone_open

(PHP 5 >= 5.2.0)

DateTimeZone::__construct -- timezone_openCreates new DateTimeZone object

Description

Object oriented style

public DateTimeZone::__construct ( string $timezone )

Procedural style

DateTimeZone timezone_open ( string $timezone )

Creates new DateTimeZone object.

Parameters

timezone

One of timezones.

Return Values

Returns DateTimeZone on success. Procedural style returns FALSE on failure.

Errors/Exceptions

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

Examples

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

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)

Коментарии

Автор:
Can be used to convert from a timezone to another.

Here from GMT to Europe/Paris :

<?php
$dt 
'Fri, 01 Mar 2024 06:47:31 GMT'// RFC 7231
$dt = new DateTime($dt);
$dt->setTimezone(new DateTimeZone('Europe/Paris'));
echo 
$dt->format('Y-m-d H:i:s'); // 2024-03-01 07:47:31
2024-03-13 03:07:37
http://php5.kiev.ua/manual/ru/datetimezone.construct.html

    Поддержать сайт на родительском проекте КГБ