← Back
browser internationalization

Internationalization API

I didn't know browser's Internacionalization API is so complete: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl

I had to use the DateTimeFormat API and I had troubles to find the valid option values. Here they go:

{
weekday: 'narrow' | 'short' | 'long',
era: 'narrow' | 'short' | 'long',
year: 'numeric' | '2-digit',
month: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long',
day: 'numeric' | '2-digit',
hour: 'numeric' | '2-digit',
minute: 'numeric' | '2-digit',
second: 'numeric' | '2-digit',
timeZoneName: 'short' | 'long',

// Time zone to express it in
timeZone: 'Asia/Shanghai',
// Force 12-hour or 24-hour
hour12: true | false,

// Rarely-used options
hourCycle: 'h11' | 'h12' | 'h23' | 'h24',
formatMatcher: 'basic' | 'best fit'
}

Notice that when a value is not provided, is not shown. For example:

formatDate(Date.now(), { day: "2-digit", month: "short" });

Produces: Abr 14 (without year)


Source: https://devhints.io/wip/intl-datetime