Java tutorial
//package com.java2s; import java.util.Calendar; public class Main { public static Calendar roundMinutesAndHour(Calendar time, int TIME_PICKER_INTERVAL) { int minute = time.get(Calendar.MINUTE); int hour = time.get(Calendar.HOUR_OF_DAY); if (time.get(Calendar.MINUTE) % TIME_PICKER_INTERVAL != 0) { int minuteFloor = minute - (minute % TIME_PICKER_INTERVAL); minute = minuteFloor + (minute == minuteFloor + 1 ? TIME_PICKER_INTERVAL : 0); if (minute == 60) { hour++; minute = 0; } } time.set(Calendar.HOUR_OF_DAY, hour); time.set(Calendar.MINUTE, minute); return time; } }