Date and Time Formatters
The date
formatter takes as a first parameter a valid JavaScript Date object, ISO 8601 date
string or a valid date and time strings.
As a second parameter it takes an object, which defines the format options.
The third optional parameter is a string representing a custom locale code. If no locale is given the
current user locale is used.
Underneath for the date formatter we use sap.ui.core.format.DateFormat and the second parameter
options
is passed unchanged to the getDateTimeInstance.
The options
and locale
parameters are optional and can be omitted. If only
options
is omitted
the locale
will be shifted in its place.
format.dateTime(date, options?, locale?)
Param | Type | Required | Description | Since |
---|---|---|---|---|
date | JS Date | Yes | Any valid value, that can construct JavaScript Date object. | 1.74 |
options | object | No | Formatting options. | 1.74 |
locale | string | No | A string representing the locale code | 1.74 |
Returns | ||||
string | The formatted date. | 1.74 |
The date
parameter can come from different places including
{parameters>/TODAY_ISO}}
, {parameters>/NOW_ISO}}
,
data binding, Date.now()
and many more.
Examples
A card with a dateTime
formatter using expression binding for today with
{pattern: 'MMMM d, y'}
as format options
"sap.card": { "type": "List", "header": { "title": "Order status {= format.dateTime(Date.now(), {pattern: 'MMMM d, y'}) }" } }Try it Out