Computer >> Computer tutorials >  >> Programming >> Javascript

How to add 30 minutes to a JavaScript Date object?


To add minutes to a JavaScript Date object, use the setMinutes() method. Under that, get the current minutes and 30 minutes to it. JavaScript date setMinutes() method sets the minutes for a specified date according to local time.

Example

You can try to run the following code to add 30 minutes to date.

<html>
   <head>
      <title>JavaScript setMinutes Method</title>
   </head>
   <body>
      <script>
         var dt = new Date();
         dt.setMinutes( dt.getMinutes() + 30 );
         document.write( dt );
      </script>
   </body>
</html>

Output

Sat Dec 15 2018 12:18:47 GMT+0530 (India Standard Time)