通过使用时刻 javascript 我只需要增加小时数(不增加或增加分钟数)/四舍五入到最近的小时或月份或年份
By use moment javascript I need to add hours only (without increase or add minutes) / round to nearest hour or month or year
通过使用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')
通过使用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')