Here you can find the source of getFromDate(boolean invoiceSearchFromFirstDayOfMonth)
public static Date getFromDate(boolean invoiceSearchFromFirstDayOfMonth)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static Date getFromDate(boolean invoiceSearchFromFirstDayOfMonth) { if (invoiceSearchFromFirstDayOfMonth) { Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH); calendar.set(Calendar.MONTH, month - 6); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } else {//from w w w.j ava 2 s .co m Calendar calendar = Calendar.getInstance(); int today = calendar.get(Calendar.DAY_OF_MONTH); int month = calendar.get(Calendar.MONTH); if (calendar.getActualMaximum(Calendar.DAY_OF_MONTH) > today) { calendar.set(Calendar.MONTH, month - 6); calendar.set(Calendar.DAY_OF_MONTH, today); } else { calendar.set(Calendar.MONTH, month - 6 - 1); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); } calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } } }