.weekday()和.format('d')之间的moment.js的区别

时间:2018-08-09 15:56:55

标签: momentjs

有人可以向我解释一下moment.js中.weekday()和.format('d')的区别吗?

例如

console.log('month: ' + month.format('DD/MM/YYYY'));

let firstDay = moment(month).startOf('M');
console.log('/1 firstDay: ' + firstDay.format('DD/MM/YYYY'));
console.log('/1 firstDay.weekday(): ' + firstDay.weekday());
console.log('/1 firstDay.format("d"): ' + firstDay.format('d'));

firstDay = moment('01/08/2018', 'DD/MM/YYYY');
console.log('/2 firstDay: ' + firstDay.format('DD/MM/YYYY'));
console.log('/2 firstDay.weekday(): ' + firstDay.weekday());
console.log('/2 firstDay.format("d"): ' + firstDay.format('d'));

产生:

month: 09/08/2018
/1 firstDay: 01/08/2018
/1 firstDay.weekday(): 2
/1 firstDay.format("d"): 3
/2 firstDay: 01/08/2018
/2 firstDay.weekday(): 3
/2 firstDay.format("d"): 3

0 个答案:

没有答案