Index Documentation

XDateTime
in package

FinalYes

Provides a set of DateTime related utilities.

Table of Contents

Methods

compare()  : int
Compares two timestamps.
compareTimeZone()  : int
Compares two timezones for sorting.
format()  : string
Formats a date and time as a string.
listTimeZones()  : array<string|int, DateTimeZone>
Generates a list of time zones.
now()  : DateTimeInterface
Returns the current date and time.
timeZoneListName()  : string
Formats a time zone as a string for a list.
toCookieString()  : string
Formats a date and time as a Cookie date/time string.
toISO8601String()  : string
Formats a date and time as an ISO-8601 string.
toRFC822String()  : string
Formats a date and time as an RFC 822 date/time string.

Methods

compare()

Compares two timestamps.

public static compare(DateTimeInterface|string|int $dt1, DateTimeInterface|string|int $dt2) : int
Parameters
$dt1 : DateTimeInterface|string|int

Base timestamp.

$dt2 : DateTimeInterface|string|int

Timestamp to compare against.

Return values
int

0 if they are equal, less than 0 if $dt1 is less than $dt2, greater than 0 if $dt1 is greater than $dt2.

compareTimeZone()

Compares two timezones for sorting.

public static compareTimeZone(DateTimeZone|string $tz1, DateTimeZone|string $tz2) : int
Parameters
$tz1 : DateTimeZone|string

Base time zone.

$tz2 : DateTimeZone|string

Time zone to compare against.

Return values
int

0 if they are equal, less than 0 if $tz1 is less than $tz2, greater than 0 if $tz1 is greater than $tz2.

format()

Formats a date and time as a string.

public static format(DateTimeInterface|string|int|null $dt, string $format) : string
Parameters
$dt : DateTimeInterface|string|int|null

Date time to format, null for now.

$format : string

DateTimeInterface::format date formatting string.

Return values
string

Provided date, formatted as requested.

listTimeZones()

Generates a list of time zones.

public static listTimeZones([bool $sort = false ][, int $group = DateTimeZone::ALL ][, string|null $countryCode = null ]) : array<string|int, DateTimeZone>
Parameters
$sort : bool = false

true if the list should be sorted.

$group : int = DateTimeZone::ALL

Group of time zones to fetch.

$countryCode : string|null = null

Country code of country of which to fetch time zones.

Return values
array<string|int, DateTimeZone>

Collection of DateTimeZone instances.

now()

Returns the current date and time.

public static now() : DateTimeInterface
Return values
DateTimeInterface

Current date and time.

timeZoneListName()

Formats a time zone as a string for a list.

public static timeZoneListName(DateTimeZone $dtz) : string
Parameters
$dtz : DateTimeZone

Time zone to format.

Return values
string

Formatted time zone string.

toCookieString()

Formats a date and time as a Cookie date/time string.

public static toCookieString(DateTimeInterface|string|int|null $dt) : string
Parameters
$dt : DateTimeInterface|string|int|null

Date time to format, null for now.

Return values
string

Cookie date time string.

toISO8601String()

Formats a date and time as an ISO-8601 string.

public static toISO8601String(DateTimeInterface|string|int|null $dt) : string
Parameters
$dt : DateTimeInterface|string|int|null

Date time to format, null for now.

Return values
string

ISO-8601 date time string.

toRFC822String()

Formats a date and time as an RFC 822 date/time string.

public static toRFC822String(DateTimeInterface|string|int|null $dt) : string
Parameters
$dt : DateTimeInterface|string|int|null

Date time to format, null for now.

Return values
string

RFC 822 date time string.


        
On this page

Search results