class DateTime extends DateTime implements JsonSerializable

Extends PHP's DateTime with strict validation and additional factory methods.

Constants

MINUTE

minute in seconds

HOUR

hour in seconds

DAY

day in seconds

WEEK

week in seconds

MONTH

average month in seconds

YEAR

average year in seconds

Methods

static DateTime
from(string|int|DateTimeInterface|null $time)

Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.

static DateTime
fromParts(int $year, int $month, int $day, int $hour = 0, int $minute = 0, float $second = 0.0)

Creates DateTime object.

static static|false
createFromFormat(string $format, string $datetime, string|DateTimeZone|null $timezone = null)

Returns a new DateTime object formatted according to the specified format.

__construct(string $datetime = 'now', DateTimeZone|null $timezone = null)

No description

modify(string $modifier)

No description

setDate(int $year, int $month, int $day)

No description

setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0)

No description

static int
relativeToSeconds(string $relativeTime)

Converts a relative time string (e.g. '10 minut') to seconds.

string
jsonSerialize()

Returns JSON representation in ISO 8601 (used by JavaScript).

string
__toString()

Returns the date and time in the format 'Y-m-d H:i:s'.

modifyClone(string $modify = '')

Returns a modified copy of the object. Use (clone $dt)->modify(...) for better type safety.

Details

at line 41
static DateTime from(string|int|DateTimeInterface|null $time)

Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.

Parameters

string|int|DateTimeInterface|null $time

Return Value

DateTime

Exceptions

Exception

at line 63
static DateTime fromParts(int $year, int $month, int $day, int $hour = 0, int $minute = 0, float $second = 0.0)

Creates DateTime object.

Parameters

int $year
int $month
int $day
int $hour
int $minute
float $second

Return Value

DateTime

Exceptions

Exception

at line 82
static static|false createFromFormat(string $format, string $datetime, string|DateTimeZone|null $timezone = null)

Returns a new DateTime object formatted according to the specified format.

Parameters

string $format
string $datetime
string|DateTimeZone|null $timezone

Return Value

static|false

at line 97
__construct(string $datetime = 'now', DateTimeZone|null $timezone = null)

No description

Parameters

string $datetime
DateTimeZone|null $timezone

at line 103
DateTime modify(string $modifier)

No description

Parameters

string $modifier

Return Value

DateTime

at line 110
DateTime setDate(int $year, int $month, int $day)

No description

Parameters

int $year
int $month
int $day

Return Value

DateTime

at line 119
DateTime setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0)

No description

Parameters

int $hour
int $minute
int $second
int $microsecond

Return Value

DateTime

at line 136
static int relativeToSeconds(string $relativeTime)

Converts a relative time string (e.g. '10 minut') to seconds.

Parameters

string $relativeTime

Return Value

int

at line 174
string jsonSerialize()

Returns JSON representation in ISO 8601 (used by JavaScript).

Return Value

string

at line 183
string __toString()

Returns the date and time in the format 'Y-m-d H:i:s'.

Return Value

string

at line 192
DateTime modifyClone(string $modify = '')

Returns a modified copy of the object. Use (clone $dt)->modify(...) for better type safety.

Parameters

string $modify

Return Value

DateTime