[英]How I can get the date this week between Monday and Sunday AngularJS
How I can get the date this week between Monday and Sunday 我如何获得本周一至周日的日期
Example the date between , this week is : Monday = 23/11/2015 to Sunday 29/11/2015 I want to get dates every week, between Monday and Sunday 例如,本周之间的日期为:星期一= 2015年11月23日至2015年11月29日,我想获取每周的日期,星期一至星期日
AngujarJS , JavaScript 脚本语言
In vanilla you could set the day of the week on a Date instance like this, 在香草中,您可以像这样在Date实例上设置星期几,
function setDay(d, day, week_starts_monday) {
var c_day = d.getDay();
if (week_starts_monday && c_day === 0)
c_day = 7; // adjust so `0` is last week sunday, 7 is this week sunday
d.setDate(d.getDate() - c_day + day);
return d;
}
So, the Monday of this week would be (today being Friday 27th) 因此,本周的星期一为(今天是星期五27日)
var d = new Date;
setDay(d, 1); // Mon Nov 23 2015 18:51:45 GMT+0000 (GMT Standard Time)
7
is the next Sunday . 7
是下一个星期日 。 0
is the previous Sunday (or the current day if it is Sunday). 0
是前一个星期日(如果是星期日,则是当前日期)。
setDay(d, 7); // Sun Nov 29 2015 18:51:45 GMT+0000 (GMT Standard Time)
You can now iterate as desired with for
, 现在,您可以遍历与期望
for
,
var i, d = new Date;
for (i = 1; i <= 7; ++i) {
setDay(d, i);
// do something with `d`
}
Please note 请注意
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.