API16:JDate/ construct
From Joomla! Documentation
Description
Constructor.
<! removed transcluded page call, red link never existed >
Syntax
__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
void
Defined in
libraries/joomla/utilities/date.php
Importing
jimport( 'joomla.utilities.date' );
Source Body
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;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples