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  .  ja  v a  2s . c o m
 * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
 * Institute of Systems Science, National University of Singapore
 *
 * Copyright 2012 Team 4(Part-Time), ISS, NUS, Singapore. All rights reserved.
 * Use of this source code is subjected to the terms of the applicable license
 * agreement.
 *
 * -----------------------------------------------------------------
 * REVISION HISTORY
 * -----------------------------------------------------------------
 * DATE             AUTHOR          REVISION      DESCRIPTION
 * 10 March 2012    Chen Changfeng   0.1            Class creating
 *                                        
 *                                        
 *                                        
 *                                        
 * 
 */

import java.util.*;

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. getEndDateForYear()
  2. getEndDateOfCurrentSemester()
  3. getEndDateOfMonth(Date given)
  4. getEndMonth(Date sessionEnd, int year, int excessDays)
  5. getEndOfDay(Date d)
  6. getEndOfDay(Date date)
  7. getEndOfDay(Date date)
  8. getEndOfDay(Date date)
  9. getEndOfDay(Date day)