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

dateTimeWithTimezone

format.dateTimeWithTimezone(date, options?, timezone?, locale?)

Param Type Required Description Since
date string|integer|Date|Array<string|integer|Date> Yes The date to be formatted. Starting with version 1.109, an array of dates can be used for options requiring multiple dates, such as for interval settings.
Each date in the array can be provided in various forms:
  • A date string that is compatible with the Date.parse() method.
  • An integer representing the number of milliseconds since January 1, 1970, 00:00:00 UTC.
  • A Date object instance.
In essence, you can use any valid single parameter of the JavaScript Date constructor. For more information, see Date() constructor.
1.143
options object No Formatting options. 1.143
timezone string No The IANA timezone ID in which the date will be calculated and formatted, such as "America/New_York". If the parameter is omitted, resolves to null or to an empty string, the timezone will be taken from Localization.getTimezone. For an invalid IANA time zone ID, an empty string will be returned. Check how the formatter is used in the sample. 1.143
locale string No A string representing the locale code. If no locale is given the current user locale is used. 1.143
Returns
string The formatted date and time with timezone. 1.143

The options, timezone and locale parameters are optional and can be omitted. If any of these parameters are not provided, the subsequent ones will self-adjust to replace the missing one/s.

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