API16

Difference between revisions of "JHtml/date"

From Joomla! Documentation

< API16:JHtml
(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...)
 
m (removing red link to edit, no existant pages)
(2 intermediate revisions by one other user not shown)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JHtml/date|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JHtml/date}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 89: Line 89:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JHtml/date|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JHtml/date}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 104: Line 104:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
 +
<source lang="php">
 +
// Server Timezone: "New York" (-0500 GMT)
 +
// User Timeszone: "Los Angeles" (-0800 GMT)
 +
 +
jimport( 'joomla.html.html' );
 +
 +
$sqlGmtTimestamp = "2012-03-01 20:00:00"
 +
 +
echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a');        // Fri March 1, 2012 12:00 pm
 +
echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a', true);  // Fri March 1, 2012 12:00 pm
 +
echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a', false); // Fri March 1, 2012 3:00 pm
 +
 +
</source>
 +
[[Category:Archived pages API16]]

Revision as of 21:55, 13 May 2013

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.

[<! removed edit link to red link >]

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

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

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />


// Server Timezone: "New York" (-0500 GMT)
// User Timeszone: "Los Angeles" (-0800 GMT)

jimport( 'joomla.html.html' );

$sqlGmtTimestamp = "2012-03-01 20:00:00"

echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a');        // Fri March 1, 2012 12:00 pm
echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a', true);  // Fri March 1, 2012 12:00 pm
echo JHtml::date($sqlGmtTimestamp , 'D F n, Y g:i a', false); // Fri March 1, 2012 3:00 pm