Moment可以根据周编号(0到6)获取日期名称。我看到鲁克逊有星期几,数字从1-7 (星期一是1,星期日是7)https://moment.github.io/luxon/#/parsing,但我不知道如何将星期数字转换为日期名称?
以分钟为单位
moment().day(0).format('ddddd'); // Sunday发布于 2021-10-22 15:02:16
我会看看卢克森的Info.weekdays,它会给出不同格式的日期名称。
然而,日期编号与Moment略有不同,因此您必须进行翻译。
const { Info } = luxon;
// moment.js days of week: Sunday: 0 -> Monday: 6
const momentDays = [0,1,2,3,4,5,6];
console.log('Index', 'Long', 'Short');
momentDays.forEach(day => {
// Luxon day indexes are Monday: 0 -> Sunday 6
const luxonDay = (day + 6) % 7;
console.log(day, Info.weekdays('long')[luxonDay], Info.weekdays('short')[luxonDay]);
}).as-console-wrapper { max-height: 100% !important; top: 0; }<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.0.2/luxon.min.js" integrity="sha512-frUCURIeB0OKMPgmDEwT3rC4NH2a4gn06N3Iw6T1z0WfrQZd7gNfJFbHrNsZP38PVXOp6nUiFtBqVvmCj+ARhw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
https://stackoverflow.com/questions/69678623
复制相似问题