At the time of using javascript, I need to add only hours (without increasing or adding minutes) / round to the nearest hour or month or year

When using js moment, when I want to add one hour to the current time, I want to increase the hour, not the minutes? So, the time 03:25 will be 04:00, not 04:25 (which is wrong)

// below increase 60 minutes while I only need to round to the nearest hour $('#eventTime').val(moment().add(1, 'hours').format('HH:mm')); 

I hope that the solution will also work during the round until the next month (until the first day of the next month) or year, etc.

+5
source share
1 answer

Using the startOf method:

 moment().startOf('hour').add(1, 'hours').format('HH:mm') 
+9
source

All Articles