Javascript:Round Time UP最近5分钟 [英] Javascript: Round Time UP nearest 5 minutes
本文介绍了Javascript:Round Time UP最近5分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在时间11:54 - 时钟是11: 55
现在时间11:56 - 时钟是12:00
它永远都不会下降,直到下一次。
我现在使用这段代码,但这也将圆滑下来
var time = 1000 * 60 * 5;
var date = new Date();
var rounded = new Date(Math.round(date.getTime()/ time)* time);
解决方案
添加2.5分钟到你的时间, / p>
11:54 + 2.5 = 11:56:30 - > 11:55
11:56 + 2.5 = 11:58:30 - > 12:00
I need to be able to round time to the next nearest 5 minutes.
Time now 11:54 - clock is 11:55
Time now 11:56 - clock is 12:00
It can never round down just always up to the next time.
I am using this code at the moment but this will round down as well
var time = 1000 * 60 * 5;
var date = new Date();
var rounded = new Date(Math.round(date.getTime() / time) * time);
解决方案
Add 2.5 minutes to your time, then round.
11:54 + 2.5 = 11:56:30 -> 11:55
11:56 + 2.5 = 11:58:30 -> 12:00
这篇关于Javascript:Round Time UP最近5分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文