Date
Extends \DateTimeDate 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 |
Joomla CMS |
Methods
__construct
Constructor.
__construct(string date = 'now', mixed tz = null) : mixed
since |
1.7.0 |
---|
Arguments
- date
string
String in a format accepted by strtotime(), defaults to "now".- tz
mixed
Time 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
string
The name of the property.
Response
mixed
A 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
string
The 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
string
The date format specification string (see {@link PHP_MANUAL#date})- local
bool
True to return the date string in the local time zone, false to return it in GMT.- translate
bool
True to translate localised strings
Response
string
The 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
int
The numeric day of the week.- abbr
bool
Return the abbreviated day string?
Response
string
The 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
string
The date format specification string (see {@link PHP_MANUAL#date})- local
bool
True to return the date string in the local time zone, false to return it in GMT.- translate
bool
True to translate localised strings
Response
string
The date string in the specified format format.
getInstance
Proxy for new Date().
getInstance(string date = 'now', mixed tz = null) : \Joomla\CMS\Date\Date
since |
1.7.3 |
---|
Arguments
- date
string
String in a format accepted by strtotime(), defaults to "now".- tz
mixed
Time 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
bool
True to return the value in hours.
Response
float
The 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
int
The numeric month of the year.- abbr
bool
If true, return the abbreviated month string
Response
string
The 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
\DateTimeZone
The 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
bool
True to return the date string in the local time zone, false to return it in GMT.
Response
string
The 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
bool
True to return the date string in the local time zone, false to return it in GMT.
Response
string
The 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
bool
True to return the date string in the local time zone, false to return it in GMT.- db
\Joomla\Database\DatabaseDriver
The database driver or null to use Factory::getDbo()
Response
string
The date string in SQL datetime format.
toUnix
Gets the date as UNIX time stamp.
toUnix() : int
since |
1.7.0 |
---|
Response
int
The 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.
gmt
Placeholder for a \DateTimeZone object with GMT as the time zone.
stz
Placeholder for a \DateTimeZone object with the default server time zone as the time zone.
tz
The \DateTimeZone object for usage in rending dates as strings.
since |
3.0.0 |
---|
Type(s)
\DateTimeZone