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

By use moment javascript I need to add hours only (without increase or add minutes) / round to nearest hour or month or year

本文关键字:添加 小时 分钟 最近 增加 时刻 javascript      更新时间:2023-09-26

通过使用moment js,当我想在当前时间上增加一个小时时,我只想增加小时而不是分钟?所以时间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'));

希望解决方案也将工作,当轮到最近的一个月(得到下个月的第一天)或年,等等…

使用startOf方法:

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