Actions

API16

JDate/ construct

From Joomla! Documentation

< API16:JDate
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Constructor.

[<! removed edit link to red link >]

<! 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 edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />