Tiny React component wrapping the ECMAScript Internationalization API with sane defaults to format dates and times.
To check some live examples of DateTime component you can go to the detail page.You can also play with react-intl-datetime-format
in a CodeSandbox.
This is the easiest way to use DateTime
formatter component:
You don't even need to pass a locale
prop, by default it will try guess the locale from the browser.
The recommended way to use it would be with a Context.Provider, this will allow you to have a global configuration so you don't need to pass props every time you format a date or time.
A provider IntlProvider
is exposed with a default config, but you can you set your own config and use it in your App
component.
The configuration object that IntlProvider
expects is basically matching the arguments from Intl.DateTimeFormat constructor.
You can import several things from react-intl-datetime-format
, let's check the possibilities:
Date
Component to format date and timesIntlProvider
to set a global configurationuseIntl
hook to update the configuration