How to add hours and minutes to a date with JavaScript?

JavascriptWeb DevelopmentFront End Technology

To add hours and minutes to a date, use the setHours() and setMinutes() method in JavaScript.

Example

You can try to run the following code to add hours and minutes −

<html>
   <head>
      <title>JavaScript Dates</title>
   </head>
   <body>
      <script>
         var dt = new Date();
         document.write("Current Date: "+dt);
         dt.setHours(dt.getHours() + 2);
         dt.setMinutes(dt.getMinutes() + 20);
         document.write("<br>Updated Date: "+dt);
      </script>
   </body>
</html>
raja
Published on 16-Feb-2018 10:18:07
Advertisements