Actions

API16

JDate/format

From Joomla! Documentation

< API16:JDate
Revision as of 17:55, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

Gets the date as a formatted string.

[Edit Descripton]

Description:JDate/format

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;
}

[Edit See Also] SeeAlso:JDate/format

Examples

<CodeExamplesForm />