Date

Extends \DateTime

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

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

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

since

1.7.0

Methods

__construct

Constructor.

__construct(string $date = 'now', mixed $tz = null) 
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.

__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|boolean

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

Arguments

$interval

\DateInterval

Response

\Joomla\CMS\Date\Date|boolean

calendar

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

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

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

$translate

booleanTrue to translate localised strings

Response

stringThe date string in the specified format format.

dayToString

Translates day of week number to a string.

dayToString(integer $day, boolean $abbr = false) : string
since

1.7.0

Arguments

$day

integerThe numeric day of the week.

$abbr

booleanReturn the abbreviated day string?

Response

stringThe day of the week.

format

Gets the date as a formatted string.

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

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

$translate

booleanTrue to translate localised strings

Response

stringThe date string in the specified format format.

getInstance

Proxy for new JDate().

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(boolean $hours = false) : float
since

1.7.0

Arguments

$hours

booleanTrue 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|boolean

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

Arguments

$modify

string

Response

\Joomla\CMS\Date\Date|boolean

monthToString

Translates month number to a string.

monthToString(integer $month, boolean $abbr = false) : string
since

1.7.0

Arguments

$month

integerThe numeric month of the year.

$abbr

booleanIf 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|boolean

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

Arguments

$interval

\DateInterval

Response

\Joomla\CMS\Date\Date|boolean

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

toSql

Gets the date as an SQL datetime string.

toSql(boolean $local = false, \JDatabaseDriver $db = null) : string
link

http://dev.mysql.com/doc/refman/5.0/en/datetime.html

since

2.5.0

Arguments

$local

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

$db

\JDatabaseDriverThe database driver or null to use \JFactory::getDbo()

Response

stringThe date string in SQL datetime format.

toUnix

Gets the date as UNIX time stamp.

toUnix() : integer
since

1.7.0

Response

integerThe date as a UNIX timestamp.

Constants

DAY_ABBR

Value "\x021\x03"

Type(s)

DAY_NAME

Value "\x022\x03"

Type(s)

MONTH_ABBR

Value "\x023\x03"

Type(s)

MONTH_NAME

Value "\x024\x03"

Type(s)

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
since

1.7.0

Type(s)

object

stz

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

static
since

1.7.0

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)

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