DateFormatter
A wrapper around Intl.DateTimeFormat that fixes various browser bugs, and polyfills new features.
| install | yarn add @internationalized/date |
|---|---|
| version | 3.10.0 |
| usage | import {DateFormatter} from '@internationalized/date' |
Introduction#
DateFormatter is a wrapper around the native Intl.DateTimeFormat API. It exposes the same API, but works around several browser bugs and provides polyfills for newer features. These are currently:
- A simple polyfill for the
formatRangeandformatRangeToPartsmethods for older browsers. - A workaround for a bug involving the
hour12option in Chrome and and the ECMAScript spec. - A workaround for a bug involving the
hourCycleoption in Safari.
See the MDN docs for full details on how to use the API.
Interface#
| Method | Description |
constructor(
(locale: string,
, options: Intl.DateTimeFormatOptions
)): void | |
format(
(value: Date
)): string | Formats a date as a string according to the locale and format options passed to the constructor. |
formatToParts(
(value: Date
)): Intl.DateTimeFormatPart[] | Formats a date to an array of parts such as separators, numbers, punctuation, and more. |
formatRange(
(start: Date,
, end: Date
)): string | Formats a date range as a string. |
formatRangeToParts(
(start: Date,
, end: Date
)): DateRangeFormatPart[] | Formats a date range as an array of parts. |
resolvedOptions(): Intl.ResolvedDateTimeFormatOptions | Returns the resolved formatting options based on the values passed to the constructor. |