How to get first and last date of the current month with JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get the first and last date of current month in JavaScript, you can try to run the following code −

<html>
   <head>
      <title>JavaScript Dates</title>
   </head>
   <body>
      <script>
         var date = new Date();
         document.write("Current Date: " + date );
         var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
         document.write("<br>"+firstDay);
         var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
         document.write("<br>"+lastDay);
      </script>
   </body>
</html>
raja
Published on 14-Feb-2018 12:47:16
Advertisements