# Date Formatter

Date Formatter is a composable that assists in formatting ISO datetime strings into human-readable formats. Optionally, JS Date object can be passed. It supports internationalization through i18n injection and provides various formatting options.

# Features

  • Reactive to locale changes through i18n injection
  • Uses native Intl.DateTimeFormat with fallback to moment.js
  • Supports multiple date and time format combinations
  • Configurable default locale

# Usage

The composable can be used with or without i18n injection. If i18n is injected, the formatter will automatically react to locale changes. When used in same component where i18n is injected - i18n can be provided in contructor options.

# Sample

# Constructor options

Name Type Default Description
locale string undefined Locale to use instead of i18n
i18n I18n undefined Default I18n to be used. Use only in edge case scenario when composable needs to be used in same component where i18n is injected

# Available Methods

# time(string|Date, FormatOverrides)

Returns time in 12-hour format with minutes. Example: "3:30 PM"

# dateTime(string|Date, FormatOverrides)

Returns shortened date with time. Example: "Mar 20, 2024, 3:30 PM"

# shortDate(string|Date, FormatOverrides)

Returns date in numeric format. Example: "3/20/2024"

# date(string|Date, FormatOverrides)

Returns shortened date. Example: "Mar 20, 2024"

# relative(string|Date)

Returns time elapsed from current time. Example: "1 year ago"

# Arguments

Name Type Description
date string|date ISO-8601 date string or native Date object
overrides FormatOverrides Overrides for Intl formatter. Use only for edge cases (e.g. include week day)

# Notes

  • All methods expect an ISO date string as input
  • The formatter will automatically use the browser's native Intl.DateTimeFormat if available
  • If Intl.DateTimeFormat is not supported, it will fall back to moment.js
  • The output format will vary based on the current locale
Last Updated: 6/18/2025, 9:26:05 AM