使用Moment,js获取月中的所有星期一日期 [英] Get All Monday Dates In Month using Moment,js

查看:1776
本文介绍了使用Moment,js获取月中的所有星期一日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么方法可以使用moment.js库获取当月的所有星期一日期。

Is there any way to get all the Monday DATES in the current month using moment.js library.

我知道我可以通过以下方式获得月末:

I know I can get the end of the month with:

moment().endOf('month')

但如何获得当前/任何月份的所有星期一日期。

but how to get all monday dates of current / any month.

我不想在javascript默认日期中使用某些函数图书馆。请使用Moment Js Library参考代码。

I dont want some function in javascript default date library. Please refer the code using Moment Js Library.

推荐答案

我刚刚阅读了docs并且没有找到任何返回数组,所以你需要只用循环

I've just read docs and haven't found any method that returns an array, so you need to do it only with loop

var monday = moment()
    .startOf('month')
    .day("Monday");
if (monday.date() > 7) monday.add(7,'d');
var month = monday.month();
while(month === monday.month()){
    document.body.innerHTML += "<p>"+monday.toString()+"</p>";
    monday.add(7,'d');
}

检查出来

这篇关于使用Moment,js获取月中的所有星期一日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆