Here you can find the source of getLastDayEnding(Date date, int field)
public static Calendar getLastDayEnding(Date date, int field)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Calendar getLastDayEnding(Date date, int field) { Calendar c = getCalendar(date); setToEndTimeOfTheDay(c);//from w w w. ja va 2 s . c o m c.set(field, c.getActualMaximum(field)); return c; } public static Calendar getCalendar(Date date) { Calendar calendar = GregorianCalendar.getInstance(); if (date == null) { calendar.setTime(new Date()); } else { calendar.setTime(date); } return calendar; } public static void setToEndTimeOfTheDay(Calendar c) { c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); c.set(Calendar.MILLISECOND, 999); } }