Import
import { DateFormat } from '@dnb/eufemia'
Description
A ready to use DNB date formatter. Use it wherever you want to format dates.
Good reasons to use this component:
- Makes the date formatting uniform for all DNB applications.
- Makes dates accessible to screen readers.
Good to know:
- You can render a date in different formats, depending on the locale.
- The component supports relative time, such as "2 hours ago", "in 3 days", etc.
- The component supports different date styles, such as
short,medium,long, andfull. - The component will automatically detect and format ISO 8601 duration strings.
Relevant links
Under the hood
The component uses Intl.DateTimeFormat browser API and Date.toLocaleDateString as a fallback, to format dates based on locale.
See Intl.DateTimeFormat locale documentation for accepted string formats.
The time element is used to ensure that the date is readable for screen readers.
Supported date value formats
The following formats are supported as date values for conversion:
yyyy-MM-dddd.MM.yyyydd/MM/yyyyDateobject
formatDate helper function
If you really need a formatted date string without rendering the component, you can import the utility directly:
import { formatDate } from '@dnb/eufemia/components/date-format/DateFormatUtils'formatDate('2023-01-01')
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
locale | AnyLocale | 'nb-NO' | The locale to use for formatting. |
options | Intl.DateTimeFormatOptions | { dateStyle: 'short' } | The format options following the Intl.DateTimeFormat API. |
Demos
Date styles
<P> <DateFormat dateStyle="full">2025-08-01</DateFormat> <DateFormat dateStyle="long">2025-08-01</DateFormat> <DateFormat dateStyle="medium">2025-08-01</DateFormat> <DateFormat dateStyle="short">2025-08-01</DateFormat> </P>
Inline
Payment due . Please make sure you have sufficient funds available.
<P> Payment due <DateFormat>2025-08-01</DateFormat>. Please make sure you have sufficient funds available. </P>
Date value formats
<P> <DateFormat>2025-08-01</DateFormat> <DateFormat>01.08.2025</DateFormat> <DateFormat>01/08/2025</DateFormat> <DateFormat value={new Date('2025-08-01')} /> </P>
Relative time
<P> <DateFormat value={new Date(new Date().getTime() - 30 * 1000)} relativeTime /> <DateFormat value={new Date(new Date().getTime() - 2 * 60 * 1000)} relativeTime /> <DateFormat value={new Date(new Date().getTime() - 24 * 60 * 60 * 1000)} relativeTime /> </P>
Relative time with different styles
The dateStyle property affects how durations are formatted using the browser's built-in Intl.DurationFormat API.
Short:
Medium:
Long (default):
Future dates with long style:
Different locales with short style:
Duration formatting
The DateFormat component automatically detects and formats ISO 8601 duration strings. No additional properties are needed.
PT1H= 1 hour (P = period, T = time, 1H = 1 hour)PT2H30M= 2 hours 30 minutesP1D= 1 day (P = period, 1D = 1 day)P1DT2H30M= 1 day 2 hours 30 minutesP1W= 1 week,P1M= 1 monthP1Y= 1 year
Short durations:
Longer durations:
Different locales:
<H4>Short durations:</H4> <P> <DateFormat value="PT1H" /> <DateFormat value="PT2H30M" /> <DateFormat value="PT45M" /> </P> <H4>Longer durations:</H4> <P> <DateFormat value="P1D" /> <DateFormat value="P1DT2H30M" /> <DateFormat value="P1W" /> <DateFormat value="P1M" /> <DateFormat value="P1Y" /> </P> <H4>Different locales:</H4> <P> <DateFormat value="PT2H30M" locale="en-US" /> <DateFormat value="PT2H30M" locale="nb-NO" /> <DateFormat value="PT2H30M" locale="de-DE" /> </P>
Duration with different styles
The dateStyle property affects how durations are formatted using the browser's built-in Intl.DurationFormat API.
Short:
Medium:
Long (default):
Different locales with short style:
<H4>Short:</H4> <P> <DateFormat value="PT2H30M" dateStyle="short" /> <DateFormat value="P1DT2H30M" dateStyle="short" /> </P> <H4>Medium:</H4> <P> <DateFormat value="PT2H30M" dateStyle="medium" /> <DateFormat value="P1DT2H30M" dateStyle="medium" /> </P> <H4>Long (default):</H4> <P> <DateFormat value="PT2H30M" dateStyle="long" /> <DateFormat value="P1DT2H30M" dateStyle="long" /> </P> <H4>Different locales with short style:</H4> <P> <DateFormat value="PT2H30M" dateStyle="short" locale="en-US" /> <DateFormat value="PT2H30M" dateStyle="short" locale="nb-NO" /> <DateFormat value="PT2H30M" dateStyle="short" locale="de-DE" /> </P>