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
stringcreateFromFormat()
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|falsefrom()
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
Return values
staticfromParts()
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
Return values
staticjsonSerialize()
Returns JSON representation in ISO 8601 (used by JavaScript).
public
jsonSerialize() : string
Return values
stringmodify()
public
modify(string $modifier) : static
Parameters
- $modifier : string
Return values
staticmodifyClone()
You'd better use: (clone $dt)->modify(...)
public
modifyClone([string $modify = '' ]) : static
Parameters
- $modify : string = ''
Return values
staticrelativeToSeconds()
Converts a relative time string (e.g. '10 minut') to seconds.
public
static relativeToSeconds(string $relativeTime) : int
Parameters
- $relativeTime : string
Return values
intsetDate()
public
setDate(int $year, int $month, int $day) : static
Parameters
- $year : int
- $month : int
- $day : int
Return values
staticsetTime()
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
staticapply()
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