Java Day End getEndTimeOfDayOrNow(Date date)

Here you can find the source of getEndTimeOfDayOrNow(Date date)

Description

Get the end time date-time of the given day which is 1 minute before midnight, unless the specified day is actually today, when the current date-time is returned

License

Open Source License

Parameter

Parameter Description
date The date-time

Return

The date-time for the sooner of the current time and the latest time of the specified day

Declaration

public static Date getEndTimeOfDayOrNow(Date date) 

Method Source Code


//package com.java2s;
//file LICENSE in the root of the DomainHealth distribution.

import static java.util.Calendar.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**//w  w w  .  j a va 2s .c om
     * Get the end time date-time of the given day which is 1 minute before 
     * midnight, unless the specified day is actually today, when the current 
     * date-time is returned
     * 
     * @param date The date-time
     * @return The date-time for the sooner of the current time and the latest time of the specified day
     */
    public static Date getEndTimeOfDayOrNow(Date date) {
        Date nowDate = new Date();
        Calendar nowCalendar = new GregorianCalendar();
        nowCalendar.setTime(nowDate);
        Calendar currentCalendar = new GregorianCalendar();
        currentCalendar.setTime(date);
        currentCalendar.set(HOUR_OF_DAY, 23);
        currentCalendar.set(MINUTE, 59);
        currentCalendar.set(SECOND, 59);
        date = currentCalendar.getTime();

        if (date.compareTo(nowDate) > 0) {
            date = nowDate;
        }

        return date;
    }
}

Related

  1. getEndOfTheDate(Date date)
  2. getEndOfYear(Date dt)
  3. getEndQuaterly(Date startDate)
  4. getEndSixMonthly(Date startDate)
  5. getEndTimeOfDay(Date date)
  6. getKalenderWoche(final Date date, final Locale locale)
  7. getLastDayEnding(Date date, int field)
  8. getMinllisBetween(Date beginDate, Date endDate)
  9. getMondays(Date startDate, Date endDate)