class DateTime extends DateTime (View source)

The DateTime class.

Constants

FORMAT_YMD

FORMAT_YMD_HI

FORMAT_YMD_HIS

TZ_LOCALE

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.

static void
setDefaultTimezone($tz = 'UTC')

setDefaultGMT

static void
resetDefaultTimezone()

resetDefaultTimezone

static string
convert(string $date, string $from = 'UTC', string $to = 'UTC', string $format = null)

Convert a date string to another timezone.

static string
toLocalTime(string $date, string $format = null, string $to = null)

utcToLocal

static string
toServerTime(string $date, string $format = null, string $from = null)

localToUTC

static boolean
useServerDefaultTimezone(boolean $boolean = null)

Method to set property useServerDefaultTimezone

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 JDate::$format.

static DateTime
create(string $date = 'now', mixed $tz = null)

Proxy for new DateTime.

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

Gets the date as a formatted string.

float
getOffsetFromGmt(boolean $hours = false)

Get the time offset from GMT in hours or seconds.

setTimezone(DateTimeZone|string $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, AbstractDatabaseDriver $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.

static string
getSqlFormat(AbstractDatabaseDriver $db = null)

getSqlFormat

Details

at line line 73
__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.

at line line 115
static void setDefaultTimezone($tz = 'UTC')

setDefaultGMT

Parameters

$tz

Return Value

void

at line line 127
static void resetDefaultTimezone()

resetDefaultTimezone

Return Value

void

at line line 159
static string convert(string $date, string $from = 'UTC', string $to = 'UTC', string $format = null)

Convert a date string to another timezone.

Parameters

string $date
string $from
string $to
string $format

Return Value

string

at line line 181
static string toLocalTime(string $date, string $format = null, string $to = null)

utcToLocal

Parameters

string $date
string $format
string $to

Return Value

string

at line line 199
static string toServerTime(string $date, string $format = null, string $from = null)

localToUTC

Parameters

string $date
string $format
string $from

Return Value

string

at line line 215
static boolean useServerDefaultTimezone(boolean $boolean = null)

Method to set property useServerDefaultTimezone

Parameters

boolean $boolean

Return Value

boolean

at line line 236
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.

at line line 290
string __toString()

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

Return Value

string The date as a formatted string.

at line line 305
static DateTime create(string $date = 'now', mixed $tz = null)

Proxy for new DateTime.

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

DateTime

at line line 320
string format(string $format, boolean $local = false)

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.

Return Value

string The date string in the specified format format.

at line line 348
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.

at line line 362
DateTime setTimezone(DateTimeZone|string $tz)

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

Parameters

DateTimeZone|string $tz The new DateTimeZone object.

Return Value

DateTime

at line line 385
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.

at line line 401
string toSql(boolean $local = false, AbstractDatabaseDriver $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.
AbstractDatabaseDriver $db The database driver or null to use JFactory::getDbo()

Return Value

string The date string in SQL datetime format.

at line line 417
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.

at line line 429
integer toUnix()

Gets the date as UNIX time stamp.

Return Value

integer The date as a UNIX timestamp.

at line line 441
static string getSqlFormat(AbstractDatabaseDriver $db = null)

getSqlFormat

Parameters

AbstractDatabaseDriver $db

Return Value

string