Here you can find the source of getToDate(boolean invoiceSearchFromFirstDayOfMonth)
public static Date getToDate(boolean invoiceSearchFromFirstDayOfMonth)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static Date getToDate(boolean invoiceSearchFromFirstDayOfMonth) { if (invoiceSearchFromFirstDayOfMonth) { Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); return toMidnight(calendar.getTime()); } else {//from w w w . j a v a 2 s.c o m return new Date(); } } public static Date toMidnight(Date date) { if (date == null) { return null; } Date returnDate = date; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); returnDate = calendar.getTime(); return returnDate; } }