Date

Extends \DateTime

Date is a class that stores a date and provides logic to manipulate and render that date in a variety of formats.

deprecated
property-read

t - Number of days in the given month.

N - ISO-8601 numeric representation of the day of the week.

z - The day of the year (starting from 0).

L - Whether it's a leap year.

d - Day of the month, 2 digits with leading zeros.

H - 24-hour format of an hour with leading zeros.

i - Minutes with leading zeros.

s - Seconds with leading zeros.

u - Microseconds with leading zeros.

m - Numeric representation of a month, with leading zeros.

S - English ordinal suffix for the day of the month, 2 characters.

W - Numeric representation of the day of the week.

Y - A full numeric representation of a year, 4 digits.

since

1.0

deprecated

The joomla/date package is deprecated

Methods

__construct

Constructor.

__construct(string $date = 'now', mixed $tz = null) 
since

1.0

Arguments

$date

stringString in a format accepted by strtotime(), defaults to "now".

$tz

mixedTime zone to be used for the date. Might be a string or a DateTimeZone object.

__get

Magic method to access properties of the date given by class to the format method.

__get(string $name) : mixed
since

1.0

Arguments

$name

stringThe name of the property.

Response

mixedA value if the property name is valid, null otherwise.

__toString

Magic method to render the date object in the format specified in the public static member Date::$format.

__toString() : string
since

1.0

Response

stringThe date as a formatted string.

format

Gets the date as a formatted string.

format(string $format, boolean $local = false) : string
since

1.0

Arguments

$format

stringThe date format specification string (see {@link PHP_MANUAL#date})

$local

booleanTrue to return the date string in the local time zone, false to return it in GMT.

Response

stringThe date string in the specified format format.

getOffsetFromGmt

Get the time offset from GMT in hours or seconds.

getOffsetFromGmt(boolean $hours = false) : float
since

1.0

Arguments

$hours

booleanTrue to return the value in hours.

Response

floatThe time offset from GMT either in hours or in seconds.

setTimezone

Method to wrap the setTimezone() function and set the internal time zone object.

setTimezone(\DateTimeZone $tz) : \Joomla\Date\Date
since

1.0

note

This method can't be type hinted due to a PHP bug: https://bugs.php.net/bug.php?id=61483

Arguments

$tz

\DateTimeZoneThe new DateTimeZone object.

Response

\Joomla\Date\Date

toISO8601

Gets the date as an ISO 8601 string. IETF RFC 3339 defines the ISO 8601 format and it can be found at the IETF Web site.

toISO8601(boolean $local = false) : string
link

http://www.ietf.org/rfc/rfc3339.txt

since

1.0

Arguments

$local

booleanTrue to return the date string in the local time zone, false to return it in GMT.

Response

stringThe date string in ISO 8601 format.

toRFC822

Gets the date as an RFC 822 string. IETF RFC 2822 supercedes RFC 822 and its definition can be found at the IETF Web site.

toRFC822(boolean $local = false) : string
link

http://www.ietf.org/rfc/rfc2822.txt

since

1.0

Arguments

$local

booleanTrue to return the date string in the local time zone, false to return it in GMT.

Response

stringThe date string in RFC 822 format.

toUnix

Gets the date as UNIX time stamp.

toUnix() : integer
since

1.0

Response

integerThe date as a UNIX timestamp.

Properties

format

The format string to be applied when using the __toString() magic method.

static
since

1.0

Type(s)

string

gmt

Placeholder for a DateTimeZone object with GMT as the time zone.

static
since

1.0

Type(s)

\DateTimeZone

stz

Placeholder for a DateTimeZone object with the default server time zone as the time zone.

static
since

1.0

Type(s)

\DateTimeZone

tz

The DateTimeZone object for usage in rending dates as strings.

since

1.0

Type(s)

\DateTimeZone

daysinmonth

t - Number of days in the given month.

Type(s)

string

dayofweek

N - ISO-8601 numeric representation of the day of the week.

Type(s)

string

dayofyear

z - The day of the year (starting from 0).

Type(s)

string

isleapyear

L - Whether it's a leap year.

Type(s)

boolean

day

d - Day of the month, 2 digits with leading zeros.

Type(s)

string

hour

H - 24-hour format of an hour with leading zeros.

Type(s)

string

minute

i - Minutes with leading zeros.

Type(s)

string

second

s - Seconds with leading zeros.

Type(s)

string

microsecond

u - Microseconds with leading zeros.

Type(s)

string

month

m - Numeric representation of a month, with leading zeros.

Type(s)

string

ordinal

S - English ordinal suffix for the day of the month, 2 characters.

Type(s)

string

week

W - Numeric representation of the day of the week.

Type(s)

string

year

Y - A full numeric representation of a year, 4 digits.

Type(s)

string