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.

property-read string

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 - ISO-8601 week number of year, weeks starting on Monday.

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

since

1.7.0

package

Application

Methods

__construct

Constructor.

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

1.7.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.

Response

mixed

__get

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

__get(string name) : mixed
since

1.7.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.7.0

Response

stringThe date as a formatted string.

add

add(\DateInterval interval) : \Joomla\CMS\Date\Date|bool

Adds an amount of days, months, years, hours, minutes and seconds to a Date object.

Arguments

interval

\DateInterval

Response

\Joomla\CMS\Date\Date|bool

calendar

Gets the date as a formatted string in a local calendar.

calendar(string format, bool local = false, bool translate = true) : string
since

1.7.0

Arguments

format

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

local

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

translate

boolTrue to translate localised strings

Response

stringThe date string in the specified format format.

dayToString

Translates day of week number to a string.

dayToString(int day, bool abbr = false) : string
since

1.7.0

Arguments

day

intThe numeric day of the week.

abbr

boolReturn the abbreviated day string?

Response

stringThe day of the week.

format

Gets the date as a formatted string.

format(string format, bool local = false, bool translate = true) : string
since

1.7.0

Arguments

format

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

local

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

translate

boolTrue to translate localised strings

Response

stringThe date string in the specified format format.

getInstance

Proxy for new Date().

getInstance(string date = 'now', mixed tz = null) : \Joomla\CMS\Date\Date
static
since

1.7.3

Arguments

date

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

tz

mixedTime zone to be used for the date.

Response

\Joomla\CMS\Date\Date

getOffsetFromGmt

Get the time offset from GMT in hours or seconds.

getOffsetFromGmt(bool hours = false) : float
since

1.7.0

Arguments

hours

boolTrue to return the value in hours.

Response

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

modify

modify(string modify) : \Joomla\CMS\Date\Date|bool

Alter the timestamp of this object by incre/decre-menting in a format accepted by strtotime().

Arguments

modify

string

Response

\Joomla\CMS\Date\Date|bool

monthToString

Translates month number to a string.

monthToString(int month, bool abbr = false) : string
since

1.7.0

Arguments

month

intThe numeric month of the year.

abbr

boolIf true, return the abbreviated month string

Response

stringThe month of the year.

setTimezone

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

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

1.7.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\CMS\Date\Date

sub

sub(\DateInterval interval) : \Joomla\CMS\Date\Date|bool

Subtracts an amount of days, months, years, hours, minutes and seconds from a Date object.

Arguments

interval

\DateInterval

Response

\Joomla\CMS\Date\Date|bool

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(bool local = false) : string
link
since

1.7.0

Arguments

local

boolTrue 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(bool local = false) : string
link
since

1.7.0

Arguments

local

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

Response

stringThe date string in RFC 822 format.

toSql

Gets the date as an SQL datetime string.

toSql(bool local = false, \Joomla\Database\DatabaseDriver db = null) : string
link
since

2.5.0

Arguments

local

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

db

\Joomla\Database\DatabaseDriverThe database driver or null to use Factory::getDbo()

Response

stringThe date string in SQL datetime format.

toUnix

Gets the date as UNIX time stamp.

toUnix() : int
since

1.7.0

Response

intThe date as a UNIX timestamp.

Constants

DAY_ABBR

Value "\x021\x03"

DAY_NAME

Value "\x022\x03"

MONTH_ABBR

Value "\x023\x03"

MONTH_NAME

Value "\x024\x03"

Properties

format

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

static
since

1.7.0

Type(s)

string

gmt

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

static deprecated
since

1.7.0

deprecated

5.0 Without replacement

Type(s)

object

stz

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

static deprecated
since

1.7.0

deprecated

5.0 Without replacement

Type(s)

object

tz

The \DateTimeZone object for usage in rending dates as strings.

since

3.0.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)

bool

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 - ISO-8601 week number of year, weeks starting on Monday.

Type(s)

string

year

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

Type(s)

string