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( date = 'now', tz = null) :
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( name) :
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() :
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
Date|bool
calendar
Gets the date as a formatted string in a local calendar.
calendar( format, local = false, translate = true) :
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( day, abbr = false) :
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( format, local = false, translate = true) :
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( date = 'now', 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
getOffsetFromGmt
Get the time offset from GMT in hours or seconds.
getOffsetFromGmt( hours = false) :
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( 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
Date|bool
monthToString
Translates month number to a string.
monthToString( month, abbr = false) :
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
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
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( local = false) :
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( local = false) :
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( local = false, \Joomla\Database\DatabaseDriver db = null) :
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
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() :
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
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
format
The format string to be applied when using the __toString() magic method.
since |
1.7.0 |
---|
Type(s)
string
gmt
Placeholder for a \DateTimeZone object with GMT as the time zone.
since |
1.7.0 |
---|---|
deprecated |
4.0 will be removed in 6.0 Will be removed without replacement |
Type(s)
object
stz
Placeholder for a \DateTimeZone object with the default server time zone as the time zone.
since |
1.7.0 |
---|---|
deprecated |
4.0 will be removed in 6.0 Will be removed without replacement |
Type(s)
object
tz
The \DateTimeZone object for usage in rending dates as strings.
since |
3.0.0 |
---|
Type(s)
DateTimeZone