JHtml/date: Difference between revisions
From Joomla! Documentation
m preparing for archive only |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Returns formated date according to a given format and time zone. | Returns formated date according to a given format and time zone. | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 88: | Line 86: | ||
</source> | </source> | ||
<! removed transcluded page call, red link never existed > | |||
< | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=date | category=date | ||
category=JHtml | category=JHtml | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
| Line 118: | Line 114: | ||
</source> | </source> | ||
[[Category:Archived pages API16]] | |||
Latest revision as of 01:44, 25 March 2017
Description
Returns formated date according to a given format and time zone.
<! removed transcluded page call, red link never existed >
Syntax
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
string A date translated by the given format and time zone.
Defined in
libraries/joomla/html/html.php
Importing
jimport( 'joomla.html.html' );
Source Body
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 transcluded page call, red link never existed >
Examples
Code Examples
// 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