Skip to main content
Elastic UI
Elastic UI
ComponentsPatternsContentData visualization
EUI ChangelogGitHubFigma
  • Guidelines
    • Getting started
    • Accessibility
    • Writing
    • Testing
  • Theming
    • Theme provider
    • Color mode
    • High contrast mode
    • Borders
    • Breakpoints
    • Colors
    • Sizing
    • Typography
  • Templates
    • Page template
    • Sitewide search
  • Layout
    • Accordion
    • Bottom bar
    • Flex
    • Flyout
    • Header
    • Horizontal rule
    • Modal
    • Page components
    • Page header
    • Panel
    • Popover
    • Resizable container
    • Spacer
  • Navigation
    • Breadcrumbs
    • Buttons
    • Collapsible nav
    • Context menu
    • Facet
    • Key pad menu
    • Link
    • Pagination
    • Side nav
    • Steps
    • Tabs
    • Tree view
  • Display
    • Aspect ratio
    • Avatar
    • Badge
    • Callout
    • Card
    • Comment list
    • Description list
    • Drag and drop
    • Empty prompt
    • Health
    • Icons
    • Image
    • List group
    • Loading
    • Progress
    • Skeleton
    • Stat
    • Text
    • Timeline
    • Title
    • Toast
    • Tooltip
    • Tour
  • Forms
    • Form controls
    • Form layouts
    • Form validation
    • Text controls
    • Numeric controls
    • Selection controls
    • Search and filter controls
    • Date and time controls
    • Other controls
  • Tabular content
    • Tables
    • Data grid
  • Editors & Syntax
    • Code
    • Markdown
  • Utilities
    • Accessibility
    • Auto sizer
    • Beacon
    • 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
  • Utilities
  • 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