JDate
Extends \DateTimeJDate is a class that stores a date and provides logic to manipulate and render that date in a variety of formats.
| package |
Joomla.Platform |
|---|---|
| subpackage |
Utilities |
| since |
11.1 |
Methods
__construct
Constructor.
__construct(string $date = 'now', mixed $tz = null)
| since |
11.1 |
|---|---|
| throws |
|
Arguments
- $date
stringString in a format accepted by strtotime(), defaults to "now".- $tz
mixedTime zone to be used for the date.
__get
Magic method to access properties of the date given by class to the format method.
__get(string $name) : mixed
| since |
11.1 |
|---|
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 JDate::$format.
__toString() : string
| since |
11.1 |
|---|
Response
stringThe date as a formatted string.
calendar
Gets the date as a formatted string in a local calendar.
calendar(string $format, boolean $local = false, boolean $translate = true) : string
| since |
11.1 |
|---|
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 |
11.1 |
|---|
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 |
11.1 |
|---|
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) : \JDate
| since |
11.3 |
|---|---|
| throws |
|
Arguments
- $date
stringString in a format accepted by strtotime(), defaults to "now".- $tz
mixedTime zone to be used for the date.
Response
getOffsetFromGMT
Get the time offset from GMT in hours or seconds.
getOffsetFromGMT(boolean $hours = false) : float
| since |
11.1 |
|---|
Arguments
- $hours
booleanTrue to return the value in hours.
Response
floatThe time offset from GMT either in hours or in seconds.
monthToString
Translates month number to a string.
monthToString(integer $month, boolean $abbr = false) : string
| since |
11.1 |
|---|
Arguments
- $month
integerThe numeric month of the year.- $abbr
booleanIf true, return the abbreviated month string
Response
stringThe month of the year.
setOffset
Set the date offset (in hours).
setOffset(float $offset) : boolean
| since |
11.1 |
|---|---|
| deprecated |
12.1 Use setTimezone instead. |
Arguments
- $offset
floatThe offset in hours.
Response
booleanTrue on success.
setTimezone
Method to wrap the setTimezone() function and set the internal time zone object.
setTimezone(object $tz) : \DateTimeZone
| since |
11.1 |
|---|
Arguments
- $tz
objectThe new DateTimeZone object.
Response
\DateTimeZoneThe old DateTimeZone object.
toFormat
Gets the date in a specific format
toFormat(string $format = '%Y-%m-%d %H:%M:%S', boolean $local = false) : string
Returns a string formatted according to the given format. Month and weekday names and other language dependent strings respect the current locale
| deprecated |
Use JDate::format() instead. 12.1 Use JDate::format() instead. |
|---|
Arguments
- $format
stringThe date format specification string (see {@link PHP_MANUAL#strftime})- $local
booleanTrue to return the date string in the local time zone, false to return it in GMT.
Response
stringThe date as a formatted string.
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 | |
|---|---|
| since |
11.1 |
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.
toMySQL
Gets the date as an MySQL datetime string.
toMySQL(boolean $local = false) : string
| link | |
|---|---|
| since |
11.1 |
| deprecated |
12.1 Use JDate::toSql() |
Arguments
- $local
booleanTrue to return the date string in the local time zone, false to return it in GMT.
Response
stringThe date string in MySQL datetime 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 | |
|---|---|
| since |
11.1 |
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, \JDatabase $dbo = null) : string
| link | |
|---|---|
| since |
11.4 |
Arguments
- $local
booleanTrue to return the date string in the local time zone, false to return it in GMT.- $dbo
\JDatabaseThe 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 |
11.1 |
|---|
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.
| since |
11.1 |
|---|
Type(s)
string
gmt
Placeholder for a DateTimeZone object with GMT as the time zone.
| since |
11.1 |
|---|
Type(s)
object
stz
Placeholder for a DateTimeZone object with the default server time zone as the time zone.
| since |
11.1 |
|---|
Type(s)
object
offsets
An array of offsets and time zone strings representing the available options from Joomla! CMS 1.5 and below.
| deprecated |
12.1 |
|---|---|
| since |
11.1 |
Type(s)
array
_tz
The DateTimeZone object for usage in rending dates as strings.
| since |
11.1 |
|---|
Type(s)
object