PHP Velho Oeste 2024

DateTime::__construct

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

DateTime::__constructReturns new DateTime object

Açıklama

public DateTime::__construct(string $datetime = "now", ?DateTimeZone $timezone = null)

Like DateTimeImmutable::__construct() but works with DateTime. Consider using the DateTimeImmutable and features instead.

Returns a new DateTime object.

Bağımsız Değişkenler

datetime

Bir tarih/zaman dizgesi. Geçerli biçemler Tarih ve Zaman Biçemleri bölümünde açıklanmıştır.

Enter "now" here to obtain the current time when using the $timezone parameter.

timezone

A DateTimeZone object representing the timezone of $datetime.

If $timezone is omitted or null, the current timezone will be used.

Bilginize:

The $timezone parameter and the current timezone are ignored when the $datetime parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).

Dönen Değerler

Returns a new DateTime instance.

Hatalar/İstisnalar

If an invalid Date/Time string is passed, DateMalformedStringException is thrown. Previous to PHP 8.3, this was Exception.

Sürüm Bilgisi

Sürüm: Açıklama
8.3.0 Now throws DateMalformedStringException if an invalid string is passed, instead of Exception.

Ayrıca Bakınız

add a note add a note

User Contributed Notes 1 note

up
0
php3779
2 months ago
it says the default parameter is 'now'.

but it also uses 'now' when you enter an empty string like '' despite it being a valid datetime format, expected an exception.
To Top