美文网首页
将日期转化为对应的周

将日期转化为对应的周

作者: 海山城 | 来源:发表于2019-12-02 10:31 被阅读0次

    将["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)
    

    相关文章

      网友评论

          本文标题:将日期转化为对应的周

          本文链接:https://www.haomeiwen.com/subject/zeexgctx.html