将["2019-12-02", "2019-11-11", "2019-10-09", "2018-12-12", "2020-05-01"]转化成相对于今天来说对应的周
- 使用moment,isoweek从星期一开始计算一周,week从星期日开始计算一周
const weekDate = dateList => {
return dateList.map(date => {
const diff = moment().endOf('isoWeek').diff(moment(date).endOf('isoWeek'), 'weeks');
return diff === 0 ? '本周' : diff > 0 ? `前${diff}周` : `后${Math.abs(diff)}周`;
});
};
const date = ["2019-12-02", "2019-11-11", "2019-10-09", "2018-12-12", "2020-05-01"]
weekDate(date)
网友评论