API16:JFactory/getDate
From Joomla! Documentation
Description
Return the JDate object
<! removed transcluded page call, red link never existed >
Syntax
static getDate($time= 'now', $tzOffset=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $time | 'now' | $time The initial time for the object |
| $tzOffset | null | $tzOffset The timezone offset. |
Returns
object
Defined in
libraries/joomla/factory.php
Importing
jimport( 'joomla.factory' );
Source Body
public static function getDate($time = 'now', $tzOffset = null)
{
jimport('joomla.utilities.date');
static $instances;
static $classname;
static $mainLocale;
if (!isset($instances)) {
$instances = array();
}
$language = &JFactory::getLanguage();
$locale = $language->getTag();
if (!isset($classname) || $locale != $mainLocale) {
//Store the locale for future reference
$mainLocale = $locale;
$localePath = JPATH_ROOT . DS . 'language' . DS . $mainLocale . DS . $mainLocale . '.date.php';
if ($mainLocale !== false && file_exists($localePath)) {
$classname = 'JDate'.str_replace('-', '_', $mainLocale);
JLoader::register($classname, $localePath);
if (!class_exists($classname)) {
//Something went wrong. The file exists, but the class does not, default to JDate
$classname = 'JDate';
}
} else {
//No file, so default to JDate
$classname = 'JDate';
}
}
$key = $time . '-' . $tzOffset;
// if (!isset($instances[$classname][$key])) {
$tmp = new $classname($time, $tzOffset);
//We need to serialize to break the reference
// $instances[$classname][$key] = serialize($tmp);
// unset($tmp);
// }
// $date = unserialize($instances[$classname][$key]);
// return $date;
return $tmp;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples