0
  • March 20.2017 (Monday)
  • March 21.2017 (Tuesday)
  • March 22.2017 (Wednesday)
  • March 23.2017 (Thursday)
  • ....

2 Answers2

1

Use date.js library. Such things you should do yourself

The cdn path of the library: https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js

var date= Date.monday().toString('MMMM dd.yyyy')
date += "\n"+Date.tuesday().toString('MMMM dd.yyyy')
date += "\n"+Date.wednesday().toString('MMMM dd.yyyy')
date += "\n"+Date.thursday().toString('MMMM dd.yyyy')
date += "\n"+Date.friday().toString('MMMM dd.yyyy')
date += "\n"+Date.saturday().toString('MMMM dd.yyyy')
console.log(date)
<script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
Gaurav Chaudhary
  • 1,491
  • 13
  • 28
0
// returns the first day of the current week  
function getMonday(d) {
  d = new Date(d);
  var day = d.getDay(),
      diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
  return new Date(d.setDate(diff));
}

var dayToPrint = getMonday(new Date());
for(var i=0;i<7;i++){
    alert(dayToPrint);
    dayToPrint.setDate(dayToPrint.getDate() + 1);
}

I'm not really sure of what you want but the previous code will alert each day of the current week.

Edit : And in order to have the same format as in your question :

var monthNames = [
    "January", "February", "March",
    "April", "May", "June", "July",
    "August", "September", "October",
    "November", "December"
  ];

var dayNames = [
    "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday",
    "Sunday"
 ];

function getMonday(d) {
    d = new Date(d);
    var day = d.getDay(),
    diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
    return new Date(d.setDate(diff));
}

function formatDate(d) {
    return monthNames[d.getMonth()] + " " + d.getDate() + "." + d.getFullYear() + " (" + dayNames[i] + ")"
}

var dayToPrint = getMonday(new Date());
for(var i=0;i<7;i++){
    alert(formatDate(dayToPrint));
    dayToPrint.setDate(dayToPrint.getDate() + 1);
}
Rafalon
  • 4,450
  • 2
  • 16
  • 30