Javascript Data Type How to - Add six hours to current date








Question

We would like to know how to add six hours to current date.

Answer


<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>
    var d1 = new Date();
    d1.setHours( d1.getHours() + 6 );<!-- w ww .  j  a v a 2s. com-->
    document.write( d1.toTimeString() );
</script>
</body>
</html>

The code above is rendered as follows: