Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
15分钟javascript中的整数_Javascript - Fatal编程技术网

15分钟javascript中的整数

15分钟javascript中的整数,javascript,Javascript,我试图做一个选择框,有4个选项 00,15,30,45 我想取当前时间,并将其四舍五入为15分钟的增量,然后更改值 我有 current_min = start_date.getMinutes(); $('#event-hour').val(current_min); 我玩了这个roundedMinutes=(15*Math.floor(enteredMinutes/15))但是我不能让它正常工作 使用Math.round而不是Math.floor一切都应该正常——除此之外,你的四舍五入到最接

我试图做一个选择框,有4个选项 00,15,30,45

我想取当前时间,并将其四舍五入为15分钟的增量,然后更改值

我有

current_min = start_date.getMinutes();
$('#event-hour').val(current_min);

我玩了这个
roundedMinutes=(15*Math.floor(enteredMinutes/15))
但是我不能让它正常工作

使用
Math.round
而不是
Math.floor
一切都应该正常——除此之外,你的四舍五入到最接近的
n
的等式是正确的。

使用
Math.round
而不是
Math.floor
一切都应该正常——除此之外,四舍五入到最接近的
n
的公式是正确的

currentTimeRounded = (15*Math.round(date.getMinutes()/15));

js> (15*Math.round(date.getMinutes()/15));
15
对我来说很好


对我来说效果很好。

对于此解决方案,请确保通过添加1小时并将分钟数重置为0来正确处理60值对于此解决方案,请确保通过添加1小时并将分钟数重置为0来正确处理60值