public function formatDate($params, $template = null)
    {
        $date = $this->getParam($params, "date", false);

        if ($date === false) {
            // Check if we have a timestamp
            $timestamp = $this->getParam($params, "timestamp", false);

            if ($timestamp === false) {
                // No timestamp => error
                throw new SmartyPluginException("Either date or timestamp is a mandatory parameter in format_date function");
            } else {
                $date = new \DateTime();
                $date->setTimestamp($timestamp);
            }
        } elseif (is_array($date)) {
            $keys = array_keys($date);

            $isDate = $this->arrayContains(static::$dateKeys, $keys);
            $isTime = $this->arrayContains(static::$timeKeys, $keys);

            // If this is not a date, fallback on today
            // If this is not a time, fallback on midnight
            $dateFormat = $isDate ? sprintf("%d-%d-%d", $date["year"], $date["month"], $date["day"]) : (new \DateTime())->format("Y-m-d");
            $timeFormat = $isTime ? sprintf("%d:%d:%d", $date["hour"], $date["minute"], $date["second"]) : "0:0:0";

            $date = new \DateTime(sprintf("%s %s", $dateFormat, $timeFormat));
        }

        if (!($date instanceof \DateTime)) {
            try {
                $date = new \DateTime($date);
            } catch (\Exception $e) {
                return "";
            }
        }

        $format = $this->getParam($params, "format", false);

        if ($format === false) {
            $format = DateTimeFormat::getInstance($this->requestStack->getCurrentRequest())->getFormat($this->getParam($params, "output", null));
        }

        $locale = $this->getParam($params, 'locale', false);

        if (false === $locale) {
            $value = $date->format($format);
        } else {
            $value = $this->formatDateWithLocale($date, $locale, $format);
        }

        return $value;
    }
public function formatDate($params, $template = null)
    {
        $date = $this->getParam($params, "date", false);

        if ($date === false) {
            // Check if we have a timestamp
            $timestamp = $this->getParam($params, "timestamp", false);

            if ($timestamp === false) {
                // No timestamp => error
                throw new SmartyPluginException("Either date or timestamp is a mandatory parameter in format_date function");
            } else {
                $date = new \DateTime();
                $date->setTimestamp($timestamp);
            }
        } elseif (is_array($date)) {
            $keys = array_keys($date);

            $isDate = $this->arrayContains(static::$dateKeys, $keys);
            $isTime = $this->arrayContains(static::$timeKeys, $keys);

            // If this is not a date, fallback on today
            // If this is not a time, fallback on midnight
            $dateFormat = $isDate ? sprintf("%d-%d-%d", $date["year"], $date["month"], $date["day"]) : (new \DateTime())->format("Y-m-d");
            $timeFormat = $isTime ? sprintf("%d:%d:%d", $date["hour"], $date["minute"], $date["second"]) : "0:0:0";

            $date = new \DateTime(sprintf("%s %s", $dateFormat, $timeFormat));
        }

        if (!($date instanceof \DateTime)) {
            try {
                $date = new \DateTime($date);
            } catch (\Exception $e) {
                return "";
            }
        }

        $format = $this->getParam($params, "format", false);

        if ($format === false) {
            $format = DateTimeFormat::getInstance($this->requestStack->getCurrentRequest())->getFormat($this->getParam($params, "output", null));
        }

        $locale = $this->getParam($params, 'locale', false);

        if (false === $locale) {
            $value = $date->format($format);
        } else {
            $value = $this->formatDateWithLocale($date, $locale, $format);
        }

        return $value;
    }
public function formatDate ( $ params , $ template = null ) { $ date = $ this -> getParam ( $ params , "date" , false ) ; if ( $ date === false ) { // Check if we have a timestamp $ timestamp = $ this -> getParam ( $ params , "timestamp" , false ) ; if ( $ timestamp === false ) { // No timestamp => error throw new SmartyPluginException ( "Either date or timestamp is a mandatory parameter in format_date function" ) ; } else { $ date = new \ DateTime ( ) ; $ date -> setTimestamp ( $ timestamp ) ; } } elseif ( is_array ( $ date ) ) { $ keys = array_keys ( $ date ) ; $ isDate = $ this -> arrayContains ( static :: $ dateKeys , $ keys ) ; $ isTime = $ this -> arrayContains ( static :: $ timeKeys , $ keys ) ; // If this is not a date, fallback on today // If this is not a time, fallback on midnight $ dateFormat = $ isDate ? sprintf ( "%d-%d-%d" , $ date [ "year" ] , $ date [ "month" ] , $ date [ "day" ] ) : ( new \ DateTime ( ) ) -> format ( "Y-m-d" ) ; $ timeFormat = $ isTime ? sprintf ( "%d:%d:%d" , $ date [ "hour" ] , $ date [ "minute" ] , $ date [ "second" ] ) : "0:0:0" ; $ date = new \ DateTime ( sprintf ( "%s %s" , $ dateFormat , $ timeFormat ) ) ; } if ( ! ( $ date instanceof \ DateTime ) ) { try { $ date = new \ DateTime ( $ date ) ; } catch ( \ Exception $ e ) { return "" ; } } $ format = $ this -> getParam ( $ params , "format" , false ) ; if ( $ format === false ) { $ format = DateTimeFormat :: getInstance ( $ this -> requestStack -> getCurrentRequest ( ) ) -> getFormat ( $ this -> getParam ( $ params , "output" , null ) ) ; } $ locale = $ this -> getParam ( $ params , 'locale' , false ) ; if ( false === $ locale ) { $ value = $ date -> format ( $ format ) ; } else { $ value = $ this -> formatDateWithLocale ( $ date , $ locale , $ format ) ; } return $ value ; }
return date in expected format

available parameters :
date => DateTime object (mandatory)
format => expected format
output => list of default system format. Values available :
date => date format
time => time format
datetime => datetime format (default)

ex :
{format_date date=$dateTimeObject format="Y-m-d H:i:s"} will output the format with specific format
{format_date date=$dateTimeObject format="l F j" locale="fr_FR"} will output the format with specific format (see date() function)
{format_date date=$dateTimeObject output="date"} will output the date using the default date system format
{format_date date=$dateTimeObject} will output with the default datetime system format

@param  array                                                  $params
@param  null                                                   $template
@throws \TheliaSmarty\Template\Exception\SmartyPluginException
@return string
return date in expected format