Date in javascript [closed]

1

How can I determine a specific day and know how many will be here at a certain date, for example: If I want to know how many times will San Juan fall on Saturday from here to 2100. I imagine that I should do several conditions but I do not know how to expose it in code could someone help?

Greetings.

    
asked by Eduardo 23.10.2017 в 12:13
source

1 answer

2

You only have to create the Date objects corresponding to each year between now and 2100 and check the day of the week with the getDay method:

var cont = 0;
for(var year=(new Date()).getFullYear()+1; year<=2100; year++){
  var sanJuan = new Date(year, 5, 23);
  if (sanJuan.getDay()===6){
    console.log('El ' + sanJuan.toLocaleDateString() + ' caerá en sábado.');
    cont++;
  }
}

console.log('De aquí al 2100 San Juan caerá en sábado ' + cont + ' veces.');
    
answered by 23.10.2017 / 12:30
source