Skip to main content
Elastic UI
Elastic UI
Getting startedComponentsUtilitiesPatternsContentData visualization
EUI ChangelogGitHubFigma
  • Accessibility
  • Auto sizer
  • Color palettes
  • Copy
  • CSS utility classes
  • Delay
  • Error boundary
  • Focus trap
  • Highlight and mark
  • HTML ID generator
  • I18n
  • Inner text
  • Mutation observer
  • Outside click detector
  • Overlay mask
  • Portal
  • Pretty duration
  • Provider
  • Resize observer
  • Scroll
  • Text diff
  • Text truncation
  • Window events
  • EUI
  • Pretty duration

Pretty duration

Use the

<PrettyDuration /> component (for JSX display) or usePrettyDuration() hook (for attribute strings) to convert a start and end date string to a human-friendly format. Both utilities take the following props:

  • timeFrom and timeTo accept start and end date values for the duration. These can be timestamps (2018-01-17T18:57:57.149Z) or relative times (now-15m).

  • dateFormat specifies the output date/time format.

  • quickRanges optionally accepts an array of quick range values that are used to pretty format custom ranges. If no custom quick ranges are passed, EUI will default to a set of common duration ranges defined below.

Show default common duration ranges
โœ„๐˜—
json code block:
โœ„๐˜—[ { "start": "now/d", "end": "now/d", "label": "Today" }, { "start": "now/w", "end": "now/w", "label": "This week" }, { "start": "now/M", "end": "now/M", "label": "This month" }, { "start": "now/y", "end": "now/y", "label": "This year" }, { "start": "now-1d/d", "end": "now-1d/d", "label": "Yesterday" }, { "start": "now/w", "end": "now", "label": "Week to date" }, { "start": "now/M", "end": "now", "label": "Month to date" }, { "start": "now/y", "end": "now", "label": "Year to date" } ]
Loading...

Props

usePrettyDuration

๐˜‚๐˜‚
โœ„๐˜—โœ„๐˜—
Prop
โ†ฆ
Description and type
โ†ฆ
Default value
โ†ต
Prop
timeFrom#
โ†ฆ
Description and type
Type: string
โ†ฆ
Default value
Required
โ†ต
Prop
timeTo#
โ†ฆ
Description and type
Type: string
โ†ฆ
Default value
Required
โ†ต
Prop
dateFormat#
โ†ฆ
Description and type
Type: string
โ†ฆ
Default value
Required
โ†ต
Prop
quickRanges#
โ†ฆ
Description and type
Type: DurationRange[]
โ†ฆ
Default value
โ†ต
๐˜‚๐˜‚
Edit this page

Previous
Portal
Next
Provider
  • Props
EUI is dual-licensed under Elastic License 2.0 and Server Side Public License, v 1 | Crafted with โค by Elastic