I am trying to have a function which displays the dates from today to sunday. So my function is like this:
dateSets() {
const currentDate = new Date();
const today = new Date();
const sunday = new Date(
currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 7)
);
const dates = [];
for (let i = today.getDate(); i <= sunday.getDate(); i++) {
dates.push(today);
today.setDate(today.getDate() + 1);
}
console.log(dates);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
console.log(tomorrow);
}
But the output is like this:
[Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time),
Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time),
Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time),
Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time),
Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time),
Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time),
Mon Aug 09 2021 14: 16: 38 GMT + 0200(Central European Summer Time)]
Table.vue:203 Tue Aug 10 2021 14:16:38 GMT+0200 (Central European Summer Time)
So, it should display from today which is 2nd of August but it displays wrong.
Thanks.