API16

JDate/format

< API16:JDate

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

Gets the date as a formatted string.


<! removed transcluded page call, red link never existed >

Syntax

format($format, $local=true)
Parameter Name Default Value Description
$format The date format specification string (see )
$local true True to return the date string in the local time zone, false to return it in GMT.

Returns

string The date string in the specified format format.

Defined in

libraries/joomla/utilities/date.php

Importing

jimport( 'joomla.utilities.date' );

Source Body

public function format($format, $local = true)
{
        // Do string replacements for date format options that can be translated.
        $format = preg_replace('/(^|[^\\\])D/', "\\1".self::DAY_ABBR, $format);
        $format = preg_replace('/(^|[^\\\])l/', "\\1".self::DAY_NAME, $format);
        $format = preg_replace('/(^|[^\\\])M/', "\\1".self::MONTH_ABBR, $format);
        $format = preg_replace('/(^|[^\\\])F/', "\\1".self::MONTH_NAME, $format);

        // If the returned time should not be local use GMT.
        if (!$local) {
                parent::setTimezone(self::$gmt);
        }

        // Format the date.
        $return = parent::format($format);

        // Manually modify the month and day strings in the formated time.
        if (strpos($return, self::DAY_ABBR) !== false) {
                $return = str_replace(self::DAY_ABBR, $this->_dayToString(parent::format('w'), true), $return);
        }
        if (strpos($return, self::DAY_NAME) !== false) {
                $return = str_replace(self::DAY_NAME, $this->_dayToString(parent::format('w')), $return);
        }
        if (strpos($return, self::MONTH_ABBR) !== false) {
                $return = str_replace(self::MONTH_ABBR, $this->_monthToString(parent::format('n'), true), $return);
        }
        if (strpos($return, self::MONTH_NAME) !== false) {
                $return = str_replace(self::MONTH_NAME, $this->_monthToString(parent::format('n')), $return);
        }

        if (!$local) {
                parent::setTimezone($this->_tz);
        }


        return $return;
}


<! removed transcluded page call, red link never existed >

Examples

Code Examples


Advertisement