通过使用时刻javascript我需要添加小时(不增加或添加分钟)/圆到最近的小时或月或年

Bas*_*maa 5 javascript jquery momentjs

通过使用时刻js,当我想加1小时到当前时间时,我只想增加小时而不是分钟?所以时间03:25将是04:00而不是04:25(这是错误的)

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

希望解决方案在圆到最近的月份(到下个月的第一天)或一年等时也能正常工作......

And*_*rey 9

使用startOf方法:

moment().startOf('hour').add(1, 'hours').format('HH:mm')
Run Code Online (Sandbox Code Playgroud)