f:format.date¶
This f:format.date viewhelper can produce date-time strings in a variety of formats.
Properties¶
date¶
- Type
datemust be aDateTimeobject, or a string that can be converted to aDateTimeobject, or an integer Unix timestamp.
Description
'17.01.1979'for example is accepted whereas'17.01.79'will not work.
datecan be a textual relative time description such as'now'or'-1 year'or'next Thursday'.If
dateisnullthe ViewHelper returns an empty string.As of TYPO3 CMS 7
datedefaults tonowif it is an empty string.If
dateis an integer it is considered to be a Unix timestamp that gets converted to aDateTimeobject with the PHP default timezone applied. The timezone is determined by the PHP functiondate_default_timezone_get(). Recommended reading: PHP: Getting the default timezone.
- Default value
- NULL
- Mandatory
- No
format¶
- Type
- String
- Description
formatis a string that describes the desired form of the produced date-time string. If there is at least one % character in the format string, the rules of PHP's strftime() will be used. Otherwise the rules of PHP's date() function will be applied.- Default value
The basic default is
'Y-m-d'This can be overridden by setting
$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] = 'd-m-Y';, for example.- Mandatory
- No
base¶
- Type
basemust be aDateTimeobject, or a string that can be converted to aDateTimeobject, or an integer Unix timestamp.- Description
- As of TYPO3 CMS 7 this ViewHelper uses
baseas the$nowparameter in PHP's strtotime() function. In that casebaseconstitutes the start time for calculations of textual relative time descriptions. - Default value
- The
now()equivalent. - Mandatory
- No
Examples¶
Now¶
<f:format.date date="now" format="d/m/y" />
Format Unix timestamps¶
<f:format.date format="d.m.Y">@1334439765</f:format.date>
<f:format.date format="d.m.Y">1334439765</f:format.date>
Format and base defaults¶
<f:format.date>{dateObject}</f:format.date>
<f:format.date>now</f:format.date>
Hours:minutes¶
<f:format.date format="H:i">{dateObject}</f:format.date>
A year before base time¶
<f:format.date format="Y" base="{dateObject}">-1 year</f:format.date>
<f:format.date format="Y-m-d" base="2016-06-06">-1 year</f:format.date>
<f:format.date format="Y-m-d" base="yesterday">-1 year</f:format.date>
<f:format.date format="Y-m-d H:i:s" base="1334439765">-1 year</f:format.date>
<f:format.date format="Y-m-d H:i:s" base="@1334439765">-1 year</f:format.date>
A more complex textual relative time¶
<f:format.date format="d.m.Y - H:i:s">+1 week 2 days 4 hours 2 seconds</f:format.date>
Localized time using strftime syntax¶
<f:format.date format="%d. %B %Y">{dateObject}</f:format.date>
<f:format.date format="%d. %B %Y">now</f:format.date>
Inline notation¶
{f:format.date(date: dateObject)}
{f:format.date(date: dateObject, format: "%d. %B %Y")}
{f:format.date(date: "now", format: "%c")}
More inline notation¶
{dateObject -> f:format.date()}
{dateObject -> f:format.date(format: 'Y-m-d H:i:s')}