Date.getMonth() with switch statement : getMonth « Date « JavaScript Tutorial






<html>
   <script language="JavaScript">
    <!--
    function getMonthString(num)
    {

      var month;    //Create a local variable to hold the string
      switch(num)
      {
        case 0:
          month="January";
          break;
        case 1:
          month="February";
          break;
        case 2:
          month="March";
          break;
        case 3:
          month="April";
          break;
        case 4:
          month="May";
          break;
        case 5:
          month="June";
          break;
        case 6:
          month="July";
          break;
        case 7:
          month="August";
          break;
        case 8:
          month="September";
          break;
        case 9:
          month="October";
          break;
        case 10:
          month="November";
          break;
        case 11:
          month="December";
          break;
        default:
          month="Invalid month";
      }
      return month;
    }
    theDate = new Date();
    document.write("The month is ",getMonthString(theDate.getMonth()));
    -->
    </script>
    </html>








12.11.getMonth
12.11.1.Date.getMonth
12.11.2.Translate the Date().getMonth() to month name
12.11.3.Date.getMonth() with switch statement