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
1 Answer
Reset to default 9Using startOf
method:
moment().startOf('hour').add(1, 'hours').format('HH:mm')
本文标签:
版权声明:本文标题:jquery - By use moment javascript I need to add hours only (without increase or add minutes)round to nearest hour or month or ye 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741302774a2371189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论