API16:JDate/toFormat
From Joomla! Documentation
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 in a specific format
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
toFormat($format= '%Y-%m-%d%H:%M:%S', $local=true)
| Parameter Name | Default Value | Description |
|---|---|---|
| $format | '%Y-%m-%d%H:%M:%S' | 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 as a formatted string.
Defined in
libraries/joomla/utilities/date.php
Importing
jimport( 'joomla.utilities.date' );
Source Body
public function toFormat($format = '%Y-%m-%d %H:%M:%S', $local = true) { // Set time zone to GMT as strftime formats according locale setting. date_default_timezone_set('GMT'); // Generate the timestamp. $time = (int) parent::format('U'); // If the returned time should be local add the GMT offset. if ($local) { $time += $this->getOffsetFromGMT(); } // Manually modify the month and day strings in the format. if (strpos($format, '%a') !== false) { $format = str_replace('%a', $this->_dayToString(date('w', $time), true), $format); } if (strpos($format, '%A') !== false) { $format = str_replace('%A', $this->_dayToString(date('w', $time)), $format); } if (strpos($format, '%b') !== false) { $format = str_replace('%b', $this->_monthToString(date('n', $time), true), $format); } if (strpos($format, '%B') !== false) { $format = str_replace('%B', $this->_monthToString(date('n', $time)), $format); } // Generate the formatted string. $date = strftime($format, $time); return $date; }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
