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

Constants

DAY_ABBR

DAY_NAME

MONTH_ABBR

MONTH_NAME

Properties

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

Methods

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

Constructor.

mixed
__get( string $name)

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

string
__toString()

Magic method to render the date object in the format specified in the public static member Date::$format.

static  Date
getInstance( string $date = 'now', mixed $tz = null)

Proxy for new JDate().

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

Translates day of week number to a string.

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

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

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

Gets the date as a formatted string.

float
getOffsetFromGmt( boolean $hours = false)

Get the time offset from GMT in hours or seconds.

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

Translates month number to a string.

setTimezone( DateTimeZone $tz)

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

string
toISO8601( boolean $local = false)

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.

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

Gets the date as an SQL datetime string.

string
toRFC822( boolean $local = false)

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.

integer
toUnix()

Gets the date as UNIX time stamp.

Date|bool
add( DateInterval $interval)

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

Date|bool
sub( DateInterval $interval)

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

Date|bool
modify( string $modify)

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

Details

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

Constructor.

Parameters

string $date String in a format accepted by strtotime(), defaults to "now".
mixed $tz Time zone to be used for the date. Might be a string or a DateTimeZone object.

mixed __get( string $name)

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

Parameters

string $name The name of the property.

Return Value

mixed A value if the property name is valid, null otherwise.

string __toString()

Magic method to render the date object in the format specified in the public static member Date::$format.

Return Value

string The date as a formatted string.

static Date getInstance( string $date = 'now', mixed $tz = null)

Proxy for new JDate().

Parameters

string $date String in a format accepted by strtotime(), defaults to "now".
mixed $tz Time zone to be used for the date.

Return Value

Date

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

Translates day of week number to a string.

Parameters

integer $day The numeric day of the week.
boolean $abbr Return the abbreviated day string?

Return Value

string The day of the week.

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

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

Parameters

string $format The date format specification string (see {@link PHP_MANUAL#date})
boolean $local True to return the date string in the local time zone, false to return it in GMT.
boolean $translate True to translate localised strings

Return Value

string The date string in the specified format format.

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

Gets the date as a formatted string.

Parameters

string $format The date format specification string (see {@link PHP_MANUAL#date})
boolean $local True to return the date string in the local time zone, false to return it in GMT.
boolean $translate True to translate localised strings

Return Value

string The date string in the specified format format.

float getOffsetFromGmt( boolean $hours = false)

Get the time offset from GMT in hours or seconds.

Parameters

boolean $hours True to return the value in hours.

Return Value

float The time offset from GMT either in hours or in seconds.

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

Translates month number to a string.

Parameters

integer $month The numeric month of the year.
boolean $abbr If true, return the abbreviated month string

Return Value

string The month of the year.

Date setTimezone( DateTimeZone $tz)

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

Parameters

DateTimeZone $tz The new \DateTimeZone object.

Return Value

Date

string toISO8601( boolean $local = false)

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.

Parameters

boolean $local True to return the date string in the local time zone, false to return it in GMT.

Return Value

string The date string in ISO 8601 format.

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

Gets the date as an SQL datetime string.

Parameters

boolean $local True to return the date string in the local time zone, false to return it in GMT.
JDatabaseDriver $db The database driver or null to use \JFactory::getDbo()

Return Value

string The date string in SQL datetime format.

string toRFC822( boolean $local = false)

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.

Parameters

boolean $local True to return the date string in the local time zone, false to return it in GMT.

Return Value

string The date string in RFC 822 format.

integer toUnix()

Gets the date as UNIX time stamp.

Return Value

integer The date as a UNIX timestamp.

Date|bool add( DateInterval $interval)

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

Parameters

DateInterval $interval

Return Value

Date|bool

Date|bool sub( DateInterval $interval)

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

Parameters

DateInterval $interval

Return Value

Date|bool

Date|bool modify( string $modify)

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

Parameters

string $modify

Return Value

Date|bool