Here you can find the source of getEndTimeOfDayOrNow(Date date)
Parameter | Description |
---|---|
date | The date-time |
public static Date getEndTimeOfDayOrNow(Date date)
//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; } }