将日期转化为对应的周

2019-12-02  本文已影响0人  海山城

将["2019-12-02", "2019-11-11", "2019-10-09", "2018-12-12", "2020-05-01"]转化成相对于今天来说对应的周

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)
上一篇下一篇

猜你喜欢

热点阅读