happy_marmoset
happy_marmoset

Reputation: 2215

php - Strange contants in DateTimeZone class

There is strange constants in DateTimeZone class

class DateTimeZone {

    const UTC = 1024;
    const ALL = 2047;
    ...
}

I have tried to find any information about them. Also have tried to use them:

$dtz = new DateTimeZone(DateTimeZone::UTC); // throws Exception with message 
                                            // DateTimeZone::__construct(): Unknown or bad timezone (1024)

or

$dt = new Datetime('2016-02-01 10:00:00', DateTimeZone::UTC); // throws Exception with message
                                                              // DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given

What are they for and how to use them?

Upvotes: 3

Views: 1802

Answers (1)

ceejayoz
ceejayoz

Reputation: 180023

They're used in a few spots, like DateTimeZone::listIdentifiers, which takes stuff like DateTimeZone::EUROPE as an argument (and would give you a list of all the Europe/Whatever timezones).

You can't use them to create a DateTimeZone or DateTime because they're regional groups of multiple timezones, not specific individual timezones (the UTC one may have confused you here).

Upvotes: 5

Related Questions