Since: 5.5

interface DateTimeInterface (View source)

Constants

ATOM Since: 7.2

COOKIE Since: 7.2

deprecated ISO8601 Since: 7.2

This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons.

Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.

ISO8601_EXPANDED Since: 8.2

RFC822 Since: 7.2

RFC850 Since: 7.2

RFC1036 Since: 7.2

RFC1123 Since: 7.2

RFC2822 Since: 7.2

RFC3339 Since: 7.2

RFC3339_EXTENDED Since: 7.2

RFC7231 Since: 7.2

RSS Since: 7.2

W3C Since: 7.2

Methods

diff(DateTimeInterface $targetObject, bool $absolute = false)

(PHP 5 >=5.5.0)
Returns the difference between two DateTime objects

string
format(string $format)

(PHP 5 >=5.5.0)
Returns date formatted according to given format

int
getOffset()

(PHP 5 >=5.5.0)
Returns the timezone offset

int
getTimestamp()

(PHP 5 >=5.5.0)
Gets the Unix timestamp

DateTimeZone|false
getTimezone()

(PHP 5 >=5.5.0)
Return time zone relative to given DateTime

void
__wakeup()

(PHP 5 >=5.5.0)
The __wakeup handler

array
__serialize()

No description

void
__unserialize(array $data)

No description

int
getMicrosecond()

No description

setMicrosecond()

No description

Details

DateInterval diff(DateTimeInterface $targetObject, bool $absolute = false)

(PHP 5 >=5.5.0)
Returns the difference between two DateTime objects

Parameters

DateTimeInterface $targetObject

The date to compare to.

bool $absolute

Should the interval be forced to be positive?

Return Value

DateInterval

The https://secure.php.net/manual/en/class.dateinterval.php DateInterval} object representing the difference between the two dates.

string format(string $format)

(PHP 5 >=5.5.0)
Returns date formatted according to given format

Parameters

string $format

Format accepted by https://secure.php.net/manual/en/function.date.php date().

Return Value

string

Returns the formatted date string on success or FALSE on failure. Since PHP8, it always returns STRING.

int getOffset()

(PHP 5 >=5.5.0)
Returns the timezone offset

Return Value

int

Returns the timezone offset in seconds from UTC on success or FALSE on failure. Since PHP8, it always returns INT.

int getTimestamp()

(PHP 5 >=5.5.0)
Gets the Unix timestamp

Return Value

int

Returns the Unix timestamp representing the date.

DateTimeZone|false getTimezone()

(PHP 5 >=5.5.0)
Return time zone relative to given DateTime

Return Value

DateTimeZone|false

Returns a https://secure.php.net/manual/en/class.datetimezone.php DateTimeZone object on success or FALSE on failure.

void __wakeup()

(PHP 5 >=5.5.0)
The __wakeup handler

Return Value

void

Initializes a DateTime object.

array __serialize()

No description

Return Value

array

void __unserialize(array $data)

No description

Parameters

array $data

Return Value

void

int getMicrosecond()

Since: 8.4

No description

Return Value

int

setMicrosecond()

Since: 8.4

No description