如何设置全局默认格式选项(例如,在应用启动时),以便我始终看到两位数字的月和日?
var date = new Date(Date.UTC(2012, 11, 1, 3, 0, 0));
// Results below assume UTC timezone - your results may vary
console.log(new Intl.DateTimeFormat('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' }).format(date));
// expected output: "12/01/2012"
console.log(new Intl.DateTimeFormat('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).format(date));
// expected output: "01/12/2012"
console.log(new Intl.DateTimeFormat('de-DE', { year: 'numeric', month: '2-digit', day: '2-digit' }).format(date));
// expected output: "01.12.2012"
以下是INTL API使用的默认行为(一位数字)
var date = new Date(Date.UTC(2012, 11, 1, 3, 0, 0));
// Results below assume UTC timezone - your results may vary
console.log(new Intl.DateTimeFormat('en-US').format(date));
// expected output: "12/1/2012"
console.log(new Intl.DateTimeFormat('en-GB').format(date));
// expected output: "01/12/2012"
console.log(new Intl.DateTimeFormat('de-DE').format(date));
// expected output: "1.12.2012"