Java Day End getEndOfDay(Date date)

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

Description

Set the time component as the last seconds of the day.

License

Open Source License

Parameter

Parameter Description
date The Date to get the last seconds

Return

The date with the time component set to the last seconds of the day.

Declaration

public static Date getEndOfDay(Date date) 

Method Source Code

//package com.java2s;
/**//from   w  w w .  j a va2  s  .  c om
*  Copyright 2012 NCS Pte. Ltd. All Rights Reserved
*
*  This software is confidential and proprietary to NCS Pte. Ltd. You shall
*  use this software only in accordance with the terms of the license
*  agreement you entered into with NCS.  No aspect or part or all of this
*  software may be reproduced, modified or disclosed without full and
*  direct written authorisation from NCS.
*
*  NCS SUPPLIES THIS SOFTWARE ON AN "AS IS" BASIS. NCS MAKES NO
*  REPRESENTATIONS OR WARRANTIES, EITHER EXPRESSLY OR IMPLIEDLY, ABOUT THE
*  SUITABILITY OR NON-INFRINGEMENT OF THE SOFTWARE. NCS SHALL NOT BE LIABLE
*  FOR ANY LOSSES OR DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
*  MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/

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

public class Main {
    /**
     * Set the time component as the last seconds of the day.
     * <p>
     * The Time Component of the date returned will be set to
     * 23:59:59.
     * <p>
     * @param date The Date to get the last seconds
     * @return The date with the time component set to the last seconds
     * of the day.
     */
    public static Date getEndOfDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        // Clear the time component
        cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));

        // System.out.println( "cal.toString() = " + cal.toString() );

        return cal.getTime();
    }
}

Related

  1. getEndMonth(Date sessionEnd, int year, int excessDays)
  2. getEndOfDay(Date d)
  3. getEndOfDay(Date date)
  4. getEndOfDay(Date date)
  5. getEndOfDay(Date date)
  6. getEndOfDay(Date day)
  7. getEndOfDay(Date day)
  8. getEndOfDay(Date when)
  9. getEndOfDay(final Date date, final TimeZone timeZone)