From Joomla! Documentation

< 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.


Gets the date in a specific format

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


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.


string The date as a formatted string.

Defined in



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.

        // 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 transcluded page call, red link never existed >


Code Examples