Manipulation MomentJS

3

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

I need to make a date forecast, after the user tells me a date, I can calculate how many weeks will go by and add this to the function of the moment by increment 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 week 54 of the year.

    
asked by anonymous 01.06.2017 / 14:32

1 answer

1

You can get the day of the week by name , in the 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>
    
01.06.2017 / 16:18