Back to Factory class

Method getDate

public static \Joomla\CMS\Date\Date
getDate
(mixed $time = 'now', mixed $tzOffset = null)
Return the {@link Date} object
Parameters
  • mixed $time The initial time for the Date object
  • mixed $tzOffset The timezone offset.
Returns
  • \Joomla\CMS\Date\Date object
Since
  • 1.7.0
-
  • \Joomla\CMS\Date\Date
Class: Factory
Project: Joomla

Method getDate - Source code

/**
 * Return the {@link Date} object
 *
 * @param   mixed  $time      The initial time for the Date object
 * @param   mixed  $tzOffset  The timezone offset.
 *
 * @return  Date object
 *
 * @see     Date
 * @since   1.7.0
 */
public static function getDate($time = 'now', $tzOffset = null)
{
    static $classname;
    static $mainLocale;
    $language = self::getLanguage();
    $locale = $language->getTag();
    if (!isset($classname) || $locale != $mainLocale) {
        // Store the locale for future reference
        $mainLocale = $locale;
        if ($mainLocale !== false) {
            $classname = str_replace('-', '_', $mainLocale) . 'Date';
            if (!class_exists($classname)) {
                // The class does not exist, default to Date
                $classname = 'Joomla\\CMS\\Date\\Date';
            }
        } else {
            // No tag, so default to Date
            $classname = 'Joomla\\CMS\\Date\\Date';
        }
    }
    $key = $time . '-' . ($tzOffset instanceof \DateTimeZone ? $tzOffset->getName() : (string) $tzOffset);
    if (!isset(self::$dates[$classname][$key])) {
        self::$dates[$classname][$key] = new $classname($time, $tzOffset);
    }
    $date = clone self::$dates[$classname][$key];
    return $date;
}