简体   繁体   English

同一月的一周中的几天,moment.js

[英]days of the week in the same month, moment.js

is there any way to get the days of a week that belong to a same month from a Date Object? 有什么办法可以从日期对象中获取属于同一月份的一周中的某几天?

I mean, if saturday is 1 and sunday 2, the week would be just 1 and 2 in a week from monday to sunday. 我的意思是,如果星期六为1,星期日为2,则一周从星期一到星期日的一周将分别为1和2。 The days from monday to friday would be a previous week form me in this example. 在这个示例中,从星期一到星期五的日子将是我的前一周。

Thanks in advance. 提前致谢。

If I did understand you correctly you are looking for something like this 如果我确实正确地理解了您,那么您正在寻找类似的东西

var startDate = moment([2007, 0, 29]);
var endDate = startDate.endOf('week');
var numberOfDaysInBetween = startDate.diff(endDate, 'days');

to include the start day add +1 to number of days in between 包括开始日期,请在此之间增加+1天

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM