Documentation

DateTime extends DateTime
in package
implements JsonSerializable

DateTime.

Table of Contents

Interfaces

JsonSerializable

Constants

DAY  = 24 * self::HOUR
day in seconds
HOUR  = 60 * self::MINUTE
hour in seconds
MINUTE  = 60
minute in seconds
MONTH  = 2629800
average month in seconds
WEEK  = 7 * self::DAY
week in seconds
YEAR  = 31557600
average year in seconds

Methods

__construct()  : mixed
__toString()  : string
Returns the date and time in the format 'Y-m-d H:i:s'.
createFromFormat()  : static|false
Returns a new DateTime object formatted according to the specified format.
from()  : static
Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.
fromParts()  : static
Creates DateTime object.
jsonSerialize()  : string
Returns JSON representation in ISO 8601 (used by JavaScript).
modify()  : static
modifyClone()  : static
You'd better use: (clone $dt)->modify(...)
relativeToSeconds()  : int
Converts a relative time string (e.g. '10 minut') to seconds.
setDate()  : static
setTime()  : static
apply()  : void
handleErrors()  : void

Constants

DAY

day in seconds

public mixed DAY = 24 * self::HOUR

HOUR

hour in seconds

public mixed HOUR = 60 * self::MINUTE

MINUTE

minute in seconds

public mixed MINUTE = 60

MONTH

average month in seconds

public mixed MONTH = 2629800

WEEK

week in seconds

public mixed WEEK = 7 * self::DAY

YEAR

average year in seconds

public mixed YEAR = 31557600

Methods

__construct()

public __construct([string $datetime = 'now' ][, DateTimeZone|null $timezone = null ]) : mixed
Parameters
$datetime : string = 'now'
$timezone : DateTimeZone|null = null

__toString()

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

public __toString() : string
Return values
string

createFromFormat()

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

public static createFromFormat(string $format, string $datetime[, string|DateTimeZone|null $timezone = null ]) : static|false
Parameters
$format : string
$datetime : string
$timezone : string|DateTimeZone|null = null
Return values
static|false

from()

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

public static from(string|int|DateTimeInterface|null $time) : static
Parameters
$time : string|int|DateTimeInterface|null
Tags
throws
Exception

if the date and time are not valid.

Return values
static

fromParts()

Creates DateTime object.

public static fromParts(int $year, int $month, int $day[, int $hour = 0 ][, int $minute = 0 ][, float $second = 0.0 ]) : static
Parameters
$year : int
$month : int
$day : int
$hour : int = 0
$minute : int = 0
$second : float = 0.0
Tags
throws
Exception

if the date and time are not valid.

Return values
static

jsonSerialize()

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

public jsonSerialize() : string
Return values
string

modify()

public modify(string $modifier) : static
Parameters
$modifier : string
Return values
static

modifyClone()

You'd better use: (clone $dt)->modify(...)

public modifyClone([string $modify = '' ]) : static
Parameters
$modify : string = ''
Return values
static

relativeToSeconds()

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

public static relativeToSeconds(string $relativeTime) : int
Parameters
$relativeTime : string
Return values
int

setDate()

public setDate(int $year, int $month, int $day) : static
Parameters
$year : int
$month : int
$day : int
Return values
static

setTime()

public setTime(int $hour, int $minute[, int $second = 0 ][, int $microsecond = 0 ]) : static
Parameters
$hour : int
$minute : int
$second : int = 0
$microsecond : int = 0
Return values
static

apply()

private apply(string $datetime[, mixed $timezone = null ][, bool $ctr = false ]) : void
Parameters
$datetime : string
$timezone : mixed = null
$ctr : bool = false

handleErrors()

private handleErrors(string $value) : void
Parameters
$value : string

        
On this page

Search results