javascript – MomentJS manipulation

Question:

I'm using moment.js to validate some dates and I used the moment().weeksInYear() to check which week of the year we are.

I need to make a date prediction, after the user informs me a date, I can calculate how many weeks will elapse and I add this in the moment function by incrementing moment().weeksInYear() + semanas .

I need to manipulate the moment so that I figure out which Friday of the week I calculate.

example:

moment().weeksInYear() // retorna semana 52 
moment().weeksInYear() + semanas // retorna 54

I need to use this 54 to know the exact date of the Friday of the 54 week of the year.

Answer:

You can get the day of the week by name , in this case: friday .

 // obtendo o número da semana atual (no seu caso, é a soma das semanas). var week = moment().week(); // obtendo a sexta-feira daquela semana e convertendo em data. var friday = moment().day('friday').week(week).toDate().toString(); console.log(friday);
 <script src="https://momentjs.com/downloads/moment.min.js"></script>
Scroll to Top
AllEscort