Java Day End getEndOfDay(Date d)

Here you can find the source of getEndOfDay(Date d)

Description

Returns the last second of the day

License

Open Source License

Declaration

public static Date getEndOfDay(Date d) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**// w  ww  .j av  a2  s. com
     * Returns the last second of the day
     */
    public static Date getEndOfDay(Date d) {
        return getDateTime(d, 23, 59, 59, 999);
    }

    /**
     * Returns the passed date, at the specified time
     */
    public static Date getDateTime(int year, int mon, int day, int hr,
            int min, int sec, int ms) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, mon - 1);
        c.set(Calendar.DATE, day);
        c.set(Calendar.HOUR_OF_DAY, hr);
        c.set(Calendar.MINUTE, min);
        c.set(Calendar.SECOND, sec);
        c.set(Calendar.MILLISECOND, ms);
        return c.getTime();
    }

    /**
     * Returns the passed date, at midnight
     */
    public static Date getDateTime(int year, int mon, int day) {
        return getDateTime(year, mon, day, 0, 0, 0, 0);
    }

    /**
     * Returns the passed date, at the specified time
     */
    public static Date getDateTime(Date d, int hour, int minute,
            int second, int millisecond) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.set(Calendar.HOUR_OF_DAY, hour);
        c.set(Calendar.MINUTE, minute);
        c.set(Calendar.SECOND, second);
        c.set(Calendar.MILLISECOND, millisecond);
        return c.getTime();
    }
}

Related

  1. getEndDateByYears(Date date, int years)
  2. getEndDateForYear()
  3. getEndDateOfCurrentSemester()
  4. getEndDateOfMonth(Date given)
  5. getEndMonth(Date sessionEnd, int year, int excessDays)
  6. getEndOfDay(Date date)
  7. getEndOfDay(Date date)
  8. getEndOfDay(Date date)
  9. getEndOfDay(Date date)