var repubblica = new Date(1946, 5, 2);
var options = { month: "long", day: "numeric", year: "numeric" };
console.log(new Intl.DateTimeFormat('fr-FR').format(repubblica)); //"02/06/1946"
console.log(new Intl.DateTimeFormat('fr-FR', options).format(repubblica)); //"2 juin 1946"
console.log(new Intl.DateTimeFormat('en-US').format(repubblica)); //"6/2/1946"
console.log(new Intl.DateTimeFormat('en-US', options).format(repubblica)); //"June 2, 1946"
console.log(new Intl.DateTimeFormat('es-ES').format(repubblica)); //"2/6/1946"
console.log(new Intl.DateTimeFormat('es-ES', options).format(repubblica)); //"2 de junio de 1946"
Tutte le opzioni disponibili:
- year: 'numeric' | '2-digit'
- month: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long'
- day: 'numeric' | '2-digit'
- weekday: 'narrow' | 'short' | 'long'
- hour: 'numeric' | '2-digit'
- minute: 'numeric' | '2-digit'
- second: 'numeric' | '2-digit'
- hour12: true | false
- hourCycle: 'h11' | 'h12' | 'h23' | 'h24'
- era: 'narrow' | 'short' | 'long'
- timeZone: '' in quale timezone esprimere la data
- timeZoneName: 'short' | 'long'
- formatMatcher: 'basic' | 'best fit'