How to add 2 hours to a JavaScript Date object?

JavascriptWeb DevelopmentFront End Technology

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


You can try to run the following code to add 2 hours to date.

 Live Demo

      <title>JavaScript setHours Method</title>
         var dt = new Date();
         dt.setHours( dt.getHours() + 2 );
         document.write( dt );


Sat Dec 15 2018 15:49:50 GMT+0530 (India Standard Time)
Published on 13-Feb-2018 08:34:23