JDate/ construct
From Joomla! Documentation
< API16:JDateRevision as of 17:55, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description===
Constructor.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{De...)
Revision as of 17:55, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description===
Constructor.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{De...)
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Constructor.
Template:Description:JDate/ construct
Syntax[edit]
__construct($date= 'now', $tz=null)
Parameter Name | Default Value | Description |
---|---|---|
$date | 'now' | String in a format accepted by strtotime(), defaults to "now". |
$tz | null | Time zone to be used for the date. |
Returns[edit]
void
Defined in[edit]
libraries/joomla/utilities/date.php
Importing[edit]
jimport( 'joomla.utilities.date' );
Source Body[edit]
public function __construct($date = 'now', $tz = null)
{
// Create the base GMT and server time zone objects.
if (empty(self::$gmt) || empty(self::$stz))
{
self::$gmt = new DateTimeZone('GMT');
self::$stz = new DateTimeZone(@date_default_timezone_get());
}
// If the time zone object is not set, attempt to build it.
if (!$tz instanceof DateTimeZone)
{
if($tz === null) {
$tz = self::$gmt;
}
// Translate from offset.
elseif (is_numeric($tz)) {
$tz = new DateTimeZone(self::$offsets[(string) $tz]);
}
elseif (is_string($tz)) {
$tz = new DateTimeZone($tz);
}
}
// If the date is numeric assume a unix timestamp and convert it.
$date = is_numeric($date) ? date('c', $date) : $date;
// Call the DateTime constructor.
parent::__construct($date, $tz);
// Set the timezone object for access later.
$this->_tz = $tz;
}
[Edit See Also] Template:SeeAlso:JDate/ construct
Examples[edit]
<CodeExamplesForm />