Rounding a time to its lowest quarter-hour
Java has integer division, so you can divide the minutes by 15 and multiply them again:

int mins = calendar.get(Calendar.MINUTE);
calendar.set(Calendar.MINUTE, mins / 15 * 15);


The division will round the number of 15-minute intervals down to the nearest integer, and multiplying it back gets you the interval you want.



To do this down to the milliseconds, do the same trick but with setTime() directly:

calendar.setTimeInMillis(calendar.getTimeInMillis() / 900000 * 900000);