How to Add hours in JavaScript date object

Spread the love

In this brisk javascript instructional exercise we’ll figure out how to include hours in default javascript data object. you can without much of a stretch set hours to data object utilizing JavaScript setHours() method. Same JavaScript getHours() technique will gives back the hour (from 0 to 23) of the predetermined date and time. By utilizing these two techniques setHours() and getHours(), you can without much of a stretch add hours to Date object.

add hours to date javascript, javascript add hours and minutes to date, javascript add hours to current time, javascript set minutes, javascript sethours

Use below function to add hours to current date, Here used javaScript prototype method to inherit properties in data object.

Pass the hours as a parameter in addHours() function which you want to add to the Date object. See below example add 3 hours to current date.

Now you’ll see 3 hours will be added in current date.
If you want to apply more customisation on javascript data object you must try plugin called datejs which help you play with javascript data object.

Leave a Reply

Your email address will not be published. Required fields are marked *