Java examples for java.util:Month
month Floor
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main{ public static void main(String[] argv) throws Exception{ Calendar calendar = Calendar.getInstance(); monthFloor(calendar);/* ww w. ja v a 2 s .c om*/ } public static void monthFloor(Calendar calendar) { dayFloor(calendar); calendar.set(Calendar.DAY_OF_MONTH, 1); } public static void monthFloor(Calendar calendar, int number) { //number param for quarter and half dayFloor(calendar); calendar.set(Calendar.DAY_OF_MONTH, 1); if (number > 1) { int month = calendar.get(Calendar.MONTH); calendar.set(Calendar.MONTH, (month / number) * number); } } public static void dayFloor(Calendar calendar) { hourFloor(calendar); calendar.set(Calendar.HOUR_OF_DAY, 0); } 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); } } }