I have today = new Date();
object. I need to get first and last day of the current week. I need both variants for Sunday and Monday as a start and end day of the week. I am little bit confuse now with a code. Can your help me?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
*current date == 30.06.2016 and monday is the first day in week.
It also works for different months and years. Tested with qunit suite:
This works across year and month changes.
This works for firstday = sunday of this week and last day = saturday for this week. Extending it to run Monday to sunday is trivial.
Making it work with first and last days in different months is left as an exercise for the user
This will be useful for any date scenario.
Although the question is seeming as obsolete I have to point out a problem.
Question: What will happen at 1st January 2016?
I think most of the above solutions calculate start of week as 27.12.2016. For this reason I think, the correct calculation should be like the below simply;
Nice suggestion but you got a small problem in lastday. You should change it to: