Java Day End getLastDayEnding(Date date, int field)

Here you can find the source of getLastDayEnding(Date date, int field)

Description

get Last Day Ending

License

Open Source License

Declaration

public static Calendar getLastDayEnding(Date date, int field) 

Method Source Code


//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);
    }
}

Related

  1. getEndQuaterly(Date startDate)
  2. getEndSixMonthly(Date startDate)
  3. getEndTimeOfDay(Date date)
  4. getEndTimeOfDayOrNow(Date date)
  5. getKalenderWoche(final Date date, final Locale locale)
  6. getMinllisBetween(Date beginDate, Date endDate)
  7. getMondays(Date startDate, Date endDate)
  8. getMonthBetween(Date startDate, Date endDate)
  9. getMonthCha(Date start, Date end)