tags:

views:

48

answers:

2

I am trying to do a select box with 4 options 00,15,30,45

I want to take the current time and round it to 15 min increments, and have the value change.

I have

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

I played with this roundedMinutes=(15*Math.floor(enteredMinutes/15)) but i couldn't get it to work right.

+1  A: 

Use Math.round instead of Math.floor and everything should be ok-- other than that, your equation for rounding to the nearest n is correct.

jason
Yup that works perfecly, 11:18 rounds to 11:15
matthewb
A: 
currentTimeRounded = (15*Math.round(date.getMinutes()/15));

js> (15*Math.round(date.getMinutes()/15));
15

Works just fine for me.

CodeJoust