Java examples for java.util:Hour
hour Floor
//package com.java2s; import java.util.Calendar; public class Main { public static void main(String[] argv) throws Exception { Calendar calendar = Calendar.getInstance(); hourFloor(calendar);//from ww w.j a v a2 s . co m } public static void hourFloor(Calendar calendar) { minuteFloor(calendar); calendar.set(Calendar.MINUTE, 0); } public static void hourFloor(Calendar calendar, int number) { minuteFloor(calendar); calendar.set(Calendar.MINUTE, 0); if (number > 1) { int hours = calendar.get(Calendar.HOUR); calendar.set(Calendar.HOUR, (hours / number) * number); } } public static void minuteFloor(Calendar calendar) { secondFloor(calendar); calendar.set(Calendar.SECOND, 0); } public static void minuteFloor(Calendar calendar, int number) { secondFloor(calendar); calendar.set(Calendar.SECOND, 0); if (number > 1) { int minutes = calendar.get(Calendar.SECOND); calendar.set(Calendar.SECOND, (minutes / number) * number); } } public static void secondFloor(Calendar calendar) { calendar.set(Calendar.MILLISECOND, 0); } }