Format.date ViewHelper <f:format.date> 

ViewHelper to format an object implementing \DateTimeInterface into human-readable output.

Go to the source code of this ViewHelper: Format\DateViewHelper.php (GitHub).

Examples 

Defaults 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date>{dateObject}</f:format.date>
Copied!
Output
1980-12-13
Copied!

Depending on the current date.

Custom date format 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date format="H:i">{dateObject}</f:format.date>
Copied!
Output
01:23
Copied!

Depending on the current time.

Relative date with given time 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date format="Y" base="{dateObject}">-1 year</f:format.date>
Copied!
Output
2016
Copied!

Assuming dateObject is in 2017.

strtotime string 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date format="d.m.Y - H:i:s">+1 week 2 days 4 hours 2 seconds</f:format.date>
Copied!
Output
13.12.1980 - 21:03:42
Copied!

Depending on the current time, see https://www.php.net/manual/function.strtotime.php.

Localized dates using strftime date format 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date format="%d. %B %Y">{dateObject}</f:format.date>
Copied!
Output
13. Dezember 1980
Copied!

Depending on the current date and defined locale. In the example you see the 1980-12-13 in a german locale.

Localized dates using ICU-based date and time formatting 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date pattern="dd. MMMM yyyy" locale="de-DE">{dateObject}</f:format.date>
Copied!
Output
13. Dezember 1980
Copied!

Depending on the current date. In the example you see the 1980-12-13 in a german locale.

Localized dates using default formatting patterns 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.date pattern="FULL" locale="fr-FR">{dateObject}</f:format.date>
Copied!
Output
jeudi 9 mars 2023 à 21:40:49 temps universel coordonné
Copied!

Depending on the current date and operating system setting. In the example you see the 2023-03-09 in a french locale.

Inline notation 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
{f:format.date(date: dateObject)}
Copied!
Output
1980-12-13
Copied!

Depending on the value of {dateObject}.

Inline notation (2nd variant) 

packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
{dateObject -> f:format.date()}
Copied!
Output
1980-12-13
Copied!

Depending on the value of {dateObject}.

Arguments of the <f:format.date> ViewHelper 

base

base
Type
mixed
A base time (an object implementing DateTimeInterface or a string) used if $date is a relative date specification. Defaults to current time.

date

date
Type
mixed
Either an object implementing DateTimeInterface or a string that is accepted by DateTime constructor

format

format
Type
string
Default
''
Format String which is taken to format the Date/Time

locale

locale
Type
string
A locale format such as "nl-NL" to format the date in a specific locale, if none given, uses the current locale of the current request. Only works when pattern argument is given

pattern

pattern
Type
string
Format date based on unicode ICO format pattern given see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax. If both "pattern" and "format" arguments are given, pattern will be used.