使用相应的数字和moment.js获取星期几

时间:2016-03-04 18:39:30

标签: javascript momentjs

我尝试使用moment.js

检索一周中的相应日期
// e.dayOfTheWeek = 2;

let dayOfTheWeek = moment().day(e.dayOfTheWeek);

console.log(dayOfTheWeek);

返回以下内容

Moment {_isAMomentObject: true, _isUTC: false, _pf: Object, _locale: Locale, _d: Tue Mar 01 2016 13:35:40 GMT-0500 (Eastern Standard Time)…}

希望它返回Tuesday我做错了什么?

还尝试了let dayOfTheWeek = moment().isoWeekday(e.dayOfTheWeek);相同的结果

1 个答案:

答案 0 :(得分:1)

尝试:

moment().isoWeekday(e.dayOfTheWeek).format('dddd')