Javascript Date



JS Date. Function you need to build a calendar




 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dates</title>
</head>
<body>
    <div id="cday">Current day is: </div>
    <div id="cdate">Current date is: </div>
    <div id="cmonth">Current month is: </div>
    <div id="cyear">Current year is: </div>
    <div id="fday">First day was: </div>
    <div id="numdays">Number of days of the current month is: </div>
</body>
</html>                      
                  
                



body {
  margin: 0;
}                
              



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

monthes = ["January", "February", "March", "April", "May", "June",
                   "July", "August", "September", "October", "November", "December"];
        var date = new Date();
        var cday = date.getDay();
        // The function getDay return a number
        document.getElementById("cday").innerHTML += weekDays[cday];
        // The current date
        var cdate = date.getDate();
        document.getElementById("cdate").innerHTML += cdate;
        // Current month
        var cmonth = date.getMonth();
        // The function getMonth return the rank of the month
        document.getElementById("cmonth").innerHTML += monthes[cmonth];
        // Current year 
        var year = date.getFullYear();
        document.getElementById("cyear").innerHTML += year;
        // first day of a month
        // first day of June 2020
                        //  year  month date
        var fday = new Date(2020, 5, 1).getDay();
        document.getElementById("fday").innerHTML += weekDays[fday];
        // Numbers of days of a month
                              // Year month date (0 is the date before the selected month)
                              // 7 is august, 0 gives the last day of july
        var numdays = new Date(2020, 7, 0).getDate();
        document.getElementById("numdays").innerHTML += numdays;