<cs-format-date>
StableHelpersSince 0.1

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.

Always use ISO 8601 date strings.
Ambiguous formats like 03/04/2020 can be read as March 4 or April 3 depending on the user’s browser and locale. A valid ISO 8601 date time string parses the same for every client.

Examples

Date & Time Format

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 Format

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

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

English:
French:
Russian:

API

Importing

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

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/format-date/format-date.js';
import './cornerstone/components/format-date/format-date.js';
import CsFormatDate from '@cruglobal/cornerstone-components/react/format-date/index.js';

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
datedateThe date/time to format. If not set, the current date and time will be used. When passing a string, it's strongly recommended to use the ISO 8601 format to ensure timezones are handled correctly. To convert a date to this format in JavaScript, use date.toISOString().Date | stringnew Date()
daydayThe format for displaying the day.'numeric' | '2-digit'
eraeraThe format for displaying the era.'narrow' | 'short' | 'long'
hourhourThe format for displaying the hour.'numeric' | '2-digit'
hourFormathour-formatThe format for displaying the hour.'auto' | '12' | '24''auto'
minuteminuteThe format for displaying the minute.'numeric' | '2-digit'
monthmonthThe format for displaying the month.'numeric' | '2-digit' | 'narrow' | 'short' | 'long'
secondsecondThe format for displaying the second.'numeric' | '2-digit'
timeZonetime-zoneThe time zone to express the time in.string
timeZoneNametime-zone-nameThe format for displaying the time.'short' | 'long'
weekdayweekdayThe format for displaying the weekday.'narrow' | 'short' | 'long'
yearyearThe format for displaying the year.'numeric' | '2-digit'