我需要得到“六月”和“星期一”的“君”。问题是,如果用户的语言设置为英语以外的任何东西,那么查找英语单词的对象就不起作用了。
export const shortDate = (str: any) => {
const d = new Date(str);
const dateString =
daysOfWeek[d.getDay()].toUpperCase() +
', ' +
shortMonths[d.getMonth()] +
' ' +
d.getDate() +
nth(d.getDate());
return dateString;
};
我需要摆脱shortMonths
对象和dayOfWeek
,因为这将是不同的,当用户不是讲英语的。
发布于 2022-03-14 20:53:12
var date = new Date();
var options = { weekday: 'short', month: 'short' };
console.log(new Intl.DateTimeFormat('en-US', options).format(date));
或者像上面的塞巴斯蒂安指出一样,date.toLocaleString
const date = new Date()
console.log(date.toLocaleString('en-US', { weekday: 'short' }))
console.log(date.toLocaleString('en-US', { month: 'short' }))
https://stackoverflow.com/questions/71474087
复制相似问题