Skip to Content
Docs🏗️ ⏐ ComponentsDataDate Format

Date Format

The Date Format component simplifies the process of converting standard date formats into more readable forms or formats tailored to the user’s locale preferences. Leveraging the capabilities of date-fns  flexibility in displaying dates in both absolute and relative terms.

Quick Start

To start using the DateFormat component, import it from the reablocks library and provide the date and format props.

Examples

Basic Usage

For straightforward applications, the component can directly format the current date and time into a default format.

Relative Time

The component also supports displaying dates in relative terms, such as “3 months ago”, which can be particularly useful for content timestamps.

API

The Date Format component is highly configurable with several properties to adjust its behavior and output format:

NameTypeDefault
allowToggleboolean

Allow the user to toggle between relative and absolute time.

false
cacheKeystring

The cache key to use for storing the user’s preference.

datestring | number | Date | null

The date to format.

formatstring

The format to use.

'MM/dd/yy hh:mm:ss a'
fromNowboolean

Whether to use relative time.

addSuffixboolean

Whether to add a suffix to the relative time.

true
classNamestring

Additional CSS class names to use.

includeSecondsboolean

Whether to include seconds in the relative time.

false
emptyMessagestring

The message to display when the date is empty. Default is “N/A”.

'N/A'
themeDateFormatTheme

Theme for the DateFormat.

Design and Usability Tips

  • User Preference: Allow users to select their preferred date format settings if possible, catering to global audiences and personal preferences.
Last updated on