4 examples of 'last monday date' in JavaScript

Every line of 'last monday date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
26function getPreviousMonday(date) {
27 var date = new Date(date); //clone date to avoid changes in the parameter
28 var dayOfWeek = date.getDay();
29 var monday = date.getDate() - dayOfWeek;
30 monday += (dayOfWeek == 0 ? -6:1); // adjust when day is Sunday
31
32 return new Date(date.setDate(monday));
33}
12getLastMonday(): Date {
13 let nowDate: Date = this.clock.getDate();
14 let dayOfWeek = nowDate.getDay() ? nowDate.getDay() : 7;
15 let daysOffsetInMillis = (dayOfWeek - 1) * WeekCalculator.MILLIS_IN_DAY;
16 let lastMonday = new Date(nowDate.getTime() - daysOffsetInMillis);
17
18 lastMonday.setHours(0);
19 lastMonday.setMinutes(0);
20 lastMonday.setSeconds(0);
21 lastMonday.setMilliseconds(0);
22
23 return lastMonday;
24}
26function nextMonday(d) {
27 let monday = new Date(d);
28 monday.setDate(monday.getDate() + (1 + 7 - monday.getDay()) % 7);
29 return monday;
30}
82function sunday_last_week(date) {
83 var date = new Date(date);
84 return day_offset(date, 0 - date.getDay());
85}

Related snippets