API16

JHtml/date

From Joomla! Documentation

< API16:JHtml
Revision as of 17:45, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Returns formated date according to a given format and time zone. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JHtml/date|Edit De...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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[edit]

Returns formated date according to a given format and time zone.

[Edit Descripton]

Template:Description:JHtml/date

Syntax[edit]

static date($input= 'now', $format=null, $tz=true)
Parameter Name Default Value Description
$input 'now' String in a format accepted by strtotime(), defaults to "now".
$format null format optional format for strftime
$tz true Time zone to be used for the date. Special cases: boolean true for user setting, boolean false for server setting.

Returns[edit]

string A date translated by the given format and time zone.

Defined in[edit]

libraries/joomla/html/html.php

Importing[edit]

jimport( 'joomla.html.html' );

Source Body[edit]

public static function date($input = 'now', $format = null, $tz = true)
{
        // Get some system objects.
        $config = JFactory::getConfig();
        $user   = JFactory::getUser();

        // UTC date converted to user time zone.
        if ($tz === true)
        {
                // Get a date object based on UTC.
                $date = JFactory::getDate($input, 'UTC');

                // Set the correct time zone based on the user configuration.
                $date->setOffset($user->getParam('timezone', $config->getValue('config.offset')));
        }
        // UTC date converted to server time zone.
        elseif ($tz === false)
        {
                // Get a date object based on UTC.
                $date = JFactory::getDate($input, 'UTC');

                // Set the correct time zone based on the server configuration.
                $date->setOffset($config->getValue('config.offset'));
        }
        // No date conversion.
        elseif ($tz === null)
        {
                $date = JFactory::getDate($input);
        }
        // UTC date converted to given time zone.
        else
        {
                // Get a date object based on UTC.
                $date = JFactory::getDate($input, 'UTC');

                // Set the correct time zone based on the server configuration.
                $date->setOffset($tz);
        }

        // If no format is given use the default locale based format.
        if (!$format) {
                $format = JText::_('DATE_FORMAT_LC1');
        }

        return $date->toFormat($format);
}

[Edit See Also] Template:SeeAlso:JHtml/date

Examples[edit]

<CodeExamplesForm />