dateFormat
Formats a date variable according to a given format string. By default, the syntax of PHP's internal date function is used for formatting. However, it is possible to also define a locale as the second argument in which case the IntlDateFormatter class is used for formatting which only supports the ICU syntax. Use the :now
variable to get the current date.
@{ date | dateFormat (format) }
Parameters
- format
- A date format string using the date or ICU syntax in combination with a
locale
. - locale
- Locale information to format a local time/date according to. Note that the locale
requires the
format
parameter to use the ICU syntax.
Note that the required locale information has to be installed on the server!
Examples
The example below is taken from the pagelist template of the Skeleton theme and will return a date formatted as Month YYYY
using the date syntax.
@{ date | dateFormat ('F Y') }
The runtime variable :now
can be used to get the current date. The following example generates a simple copyright notice:
© @{ :now | dateFormat('Y') } by @{ sitename }
You can also use a variable to let the user define the date format:
@{ date | dateFormat (@{ format }) }
In order to be able to translate week days and month names according to a given locale, it is possible to use the ICU syntax syntax for the format
parameter in combination with the optional locale
parameter as follows:
@{ date | dateFormat ('EEEE, d. MMMM Y', 'de_DE') }