# Date localization ## Features - Small file size - Uses `Intl.DateFormat` but patches browser inconsistencies ## Formatting With the `formatDate` you can safely display dates for all languages. The input value is `new Date('1987/05/12')`. ```js script import { css, html } from '@lion/core'; import { formatNumber, formatNumberToParts, formatDate } from '../index.js'; import allLocales from './all-locales.js'; export default { title: 'Localize/Dates', }; const formatDateDemoStyle = css` .demo-table { border-collapse: collapse; text-align: right; } .demo-table thead > tr { border-bottom: 1px solid grey; } .demo-table thead > tr > :first-child, .demo-table tbody > tr > :first-child, .demo-table tfoot > tr > :first-child { text-align: left; } .demo-table th, .demo-table td { padding: 8px; } `; ``` ```js preview-story export const formatting = () => html`
| Output | Options | Code |
|---|---|---|
| ${formatDate(new Date('1987/05/12'))} | Default | formatDate(new Date('1987/05/12')) |
| ${formatDate(new Date('1987/05/12'), { weekday: 'long', year: 'numeric', month: 'long', day: '2-digit', })} | Date display |
formatDate(new Date(){weekday:'long',year:'numeric',month:'long',day:'2-digit'})
|
| ${formatDate(new Date('1987/05/12'), { weekday: 'long', month: 'long', day: '2-digit', })} | Date without year |
formatDate(new Date('1987/05/12'), {weekday:'long',month:'long',day:'2-digit'})
|
| ${formatDate(new Date('1987/05/12'), { weekday: 'long', year: 'numeric', day: '2-digit', })} | Date without month |
formatDate(new Date('1987/05/12'), {weekday:'long',year:'numeric',day:'2-digit'})
|
| ${formatDate(new Date('1987/05/12'), { weekday: 'long', month: 'long', year: 'numeric', })} | Date without day |
formatDate(new Date('1987/05/12'), { weekday:'long',year:'numeric',month:'long' })
|
| ${formatDate(new Date('1987/05/12'), { locale: 'nl-NL' })} | Locale | formatDate(new Date('1987/05/12'){ locale:'nl-NL' }) |
| Locale | Output |
|---|---|
| ${locale} | ${formatDate(new Date('1987/05/12'), { locale })} |
| Locale | Output |
|---|---|
| ${locale} | ${formatDate(new Date('1987/05/12'), { locale })} |