Date and Time Formatters
Format single date and time values or date and time intervals according to a set of format options.
API
dateTime
format.dateTime(date, options?, locale?)
Param | Type | Required | Description | Since |
---|---|---|---|---|
date | string|integer|Date|Array<string|integer|Date> | Yes |
The date to be formatted.
Since version 1.109 you can use an array of dates for the options which require more than 1 date, such as interval .
Each date can be given as a date string, recognized by the Date.parse() method, an integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC, or a Date instance.
In other words, any valid JavaScript Date constructor single parameter. See Date() constructor.
|
1.74 |
options | object | No | Formatting options. | 1.74 |
locale | string | No | A string representing the locale code. If no locale is given the current user locale is used. | 1.74 |
Returns | ||||
string | The formatted date and time. | 1.74 |
date
format.date(date, options?, locale?)
Param | Type | Required | Description | Since |
---|---|---|---|---|
date | string|integer|Date|Array<string|integer|Date> | Yes |
The date to be formatted.
Each date can be given as a date string, recognized by the Date.parse() method,
an integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC,
or a Date instance.
In other words, any valid JavaScript Date constructor single parameter. See Date() constructor.
|
1.120 |
options | object | No | Formatting options. | 1.120 |
locale | string | No | A string representing the locale code. If no locale is given the current user locale is used. | 1.120 |
Returns | ||||
string | The formatted date. | 1.120 |
The options
and locale
parameters are optional and can be omitted. If only
options
is omitted the locale
will be shifted in its place.
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": "Orders in the Interval {= format.date(['2020-05-05T00:00:00.000Z', Date.now()], { interval: true }) }" }, "content": { "data": { "json": [ { "Name": "Keyboard and Mouse", "CreatedAt": "/Date(1600430944000)/" }, { "Name": "ITelO Vault", "CreatedAt": 1600430944000 }, { "Name": "Notebook Professional 15", "CreatedAt": "Fri Sep 18 2020 03:24:00 GMT+0200 (Eastern European Standard Time)" }, { "Name": "Ergo Screen E-I", "CreatedAt": "Sun May 2 2021 03:24:00 GMT+0200 (Eastern European Standard Time)", }, { "Name": "Laser Professional Eco", "CreatedAt": "2020-08-17T01:24:00.000Z", } ] }, "maxItems": 4, "item": { "title": "{Name}", "description": "Created {= format.dateTime(${CreatedAt}, {relative: true}) }", } } }Try it Out