Skip to content
Advertisement

Add hours in 12 hour format using javascript / jquery

How we can add hours into 12hour format time using Javascript/JQuery?

Example:

Add 2 hour in 12:00 AM then result should be 02:00 AM
Add 8 hour in 09:00 PM then result should be 05:00 AM

Advertisement

Answer

The following function takes a string representing a time and an integer denoting the number of hours you want to add to that time. You can optionally pass an integer number of minutes as well. The result is a string formatted as ‘h:mm xm’.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement