Format Date

<wa-format-date> Stable Since 2.0

Formats a date or time for display using the specified locale and options. Powered by the Intl.DateTimeFormat API for consistent, localized output.

Localization is handled by the browser's Intl.DateTimeFormat API. No language packs are required.

The date attribute determines the date/time to use when formatting. It must be a string that Date.parse() can interpret or a Date object set via JavaScript. If omitted, the current date/time will be assumed.

When using strings, avoid ambiguous dates such as 03/04/2020 which can be interpreted as March 4 or April 3 depending on the user's browser and locale. Instead, always use a valid ISO 8601 date time string to ensure the date will be parsed properly by all clients.

Examples

Link to This Section

Date & Time Formatting

Link to This Section

Formatting options are based on those found in the Intl.DateTimeFormat API. When formatting options are provided, the date/time will be formatted according to those values. When no formatting options are provided, a localized, numeric date will be displayed instead.






Hour Formatting

Link to This Section

By default, the browser will determine whether to use 12-hour or 24-hour time. To force one or the other, set the hour-format attribute to 12 or 24.


Localization

Link to This Section

Use the lang attribute to set the date/time formatting locale.

English:
French:
Russian:

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/format-date/format-date.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/format-date/format-date.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/format-date/format-date.js';

To import this component for React 18 or below, use the following code:

import WaFormatDate from '@awesome.me/webawesome/dist/react/format-date/index.js';

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Need a hand? Report a bug Ask for help
    No results