admin管理员组

文章数量:1277876

By use moment js, When I want to add One hour to current time, I only want to increase the hour and Not the minutes? So the time 03:25 will be 04:00 and 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'));

Hope the solution will work also when round to nearest month (get to first day of next month) or year and so on ...

By use moment js, When I want to add One hour to current time, I only want to increase the hour and Not the minutes? So the time 03:25 will be 04:00 and 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'));

Hope the solution will work also when round to nearest month (get to first day of next month) or year and so on ...

Share Improve this question edited Jul 22, 2015 at 12:37 Bashar Abu Shamaa asked Jul 21, 2015 at 13:20 Bashar Abu ShamaaBashar Abu Shamaa 2,0292 gold badges22 silver badges36 bronze badges 1
  • 1 Are you trying to round the time up to the next hour? – phuzi Commented Jul 21, 2015 at 15:12
Add a ment  | 

1 Answer 1

Reset to default 9

Using startOf method:

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

本文标签: