Java Day End getEndOfHour(Date day)

Here you can find the source of getEndOfHour(Date day)

Description

Returns a Date set to the last possible millisecond of the day, just before midnight.

License

Apache License

Declaration

public static Date getEndOfHour(Date day) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*from  w ww  .j a v a 2s.co m*/
     * Returns a Date set to the last possible millisecond of the day, just
     * before midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getEndOfHour(Date day) {
        return getEndOfHour(day, Calendar.getInstance());
    }

    public static Date getEndOfHour(Date day, Calendar cal) {
        if (day == null || cal == null) {
            return day;
        }

        cal.setTime(day);
        cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
        return cal.getTime();
    }
}

Related

  1. getEndOfDay(Date day)
  2. getEndOfDay(Date day)
  3. getEndOfDay(Date when)
  4. getEndOfDay(final Date date, final TimeZone timeZone)
  5. getEndOfDay(Long date)
  6. getEndOfTheDate(Date date)
  7. getEndOfYear(Date dt)
  8. getEndQuaterly(Date startDate)
  9. getEndSixMonthly(Date startDate)