PHP Velho Oeste 2024

DateTimeImmutable::__construct

date_create_immutable

(PHP 5 >= 5.5.0, PHP 7)

DateTimeImmutable::__construct -- date_create_immutableReturns new DateTimeImmutable object

Descrierea

Stil obiect-orientat

public DateTimeImmutable::__construct ( string $datetime = "now" , DateTimeZone|null $timezone = null )

Stil procedural

date_create_immutable ( string $datetime = "now" , DateTimeZone|null $timezone = null ) : DateTimeImmutable|false

Like DateTime::__construct() but works with DateTimeImmutable.

add a note add a note

User Contributed Notes 1 note

up
0
Dmitrii
1 year ago
"If $timezone is omitted or null, the current timezone will be used." - note, that timezone IS NOT equal offset, if its important for your application.

If default timezone = Europe/Moscow, then:
echo (new \DateTimeImmutable('2014-10'))->format(DATE_ATOM); // gives "2014-10-01T00:00:00+04:00"
echo (new \DateTimeImmutable('2014-11'))->format(DATE_ATOM); // gives "2014-11-01T00:00:00+03:00"
because of law changes (abolition of "summer time").
To Top