你把选择权交给
locales
可选择的
,它只是意味着不需要为它提供值;并不意味着可以尝试跳过它。如果您不想为
区域设置
但对于
options
,通过
undefined
取而代之的是:
const date = new Date()
console.log('Date:', date)
const dateOptions = { year: 'numeric', month: 'numeric', day: 'numeric' }
const timeOptions = { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false }
const fDate = new Intl.DateTimeFormat(undefined, dateOptions).format(date)
const fTime = new Intl.DateTimeFormat(undefined, timeOptions).format(date)
console.log('fDate:', fDate)
console.log('fTime:', fTime)