How to find the dates of coming saturday and sunda

2019-09-07 17:50发布

问题:

I have set today's date in code as follows,

 public fromDate: Date = new Date();

How can i find the dates of coming saturday and sunday, mean this weekend dates from the above?

i can try by adding number of days from the current day. but is there a better solution?

回答1:

If you don't mind using an external library, you can use moment's day function.

import * as moment from 'moment';
const fromDate = moment();
const nextSunday = fromDate.day(7);
console.log(nextSunday.calendar());