【问题标题】:How to get list names of week days?如何获取工作日的列表名称?
【发布时间】:2019-02-13 12:47:09
【问题描述】:

我正在使用 momentjs,我想返回过去 7 天的所有名称。我知道我可以使用以下方法获取号码:

moment().isoWeekday();

如何获取从今天起过去 7 天的姓名列表?例如:

tuesday, monday, sunday, saturday, friday, thursday, wednesday

【问题讨论】:

    标签: momentjs


    【解决方案1】:

    这样的事情应该可以工作:

    let resultDates = []; // array to hold day names
    const current = moment(); // current date
    let n = 7; // days to go back
    while (n > 0) {
      resultDates.push(current.format("dddd")) // get day n and push it to array
      current.subtract(1, "day") // subtract a day
      n--;
    }
    
    console.log(resultDates);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js"></script>

    数组的第一个元素是今天,最后一个元素是 7 天前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-21
      • 1970-01-01
      • 2021-08-22
      • 2018-07-29
      • 1970-01-01
      • 2012-08-31
      • 2015-09-28
      • 1970-01-01
      相关资源
      最近更新 更多