class DateTime extends DateTime implements JsonSerializable

DateTime.

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 $time, string|DateTimeZone|null $timezone = null)

Returns new DateTime object formatted according to the specified format.

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 = '')

Creates a copy with a modified time.

Details

at line 45
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 67
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

InvalidArgumentException

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

Returns new DateTime object formatted according to the specified format.

Parameters

string $format
string $time
string|DateTimeZone|null $timezone

Return Value

static|false

at line 115
string jsonSerialize()

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

Return Value

string

at line 124
string __toString()

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

Return Value

string

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

Creates a copy with a modified time.

Parameters

string $modify

Return Value

DateTime

Traits

Strict class for better experience.