Java Day End toDayEnds(Date date)

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

Description

Returns a Date object that represents the ending hour,min,second of a day (i.e., 23:59:59).

License

Mozilla Public License

Parameter

Parameter Description
date an instantiated date

Return

the ending hour/min/sec of date

Declaration

public static Date toDayEnds(Date date) 

Method Source Code

//package com.java2s;
/*//from   ww w  .j av  a2 s  . c o m
 * gnizr is a trademark of Image Matters LLC in the United States.
 * 
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License
 * for the specific language governing rights and limitations under the License.
 * 
 * The Initial Contributor of the Original Code is Image Matters LLC.
 * Portions created by the Initial Contributor are Copyright (C) 2007
 * Image Matters LLC. All Rights Reserved.
 */

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

public class Main {
    /**
     * Returns a <code>Date</code> object that represents the ending
     * hour,min,second of a day (i.e., 23:59:59). The returned object shares the
     * same year, month, day values as the input <code>date</code>
     * 
     * @param date
     *            an instantiated date
     * @return the ending hour/min/sec of <code>date</code>
     */
    public static Date toDayEnds(Date date) {
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(date);
        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));
        return cal.getTime();
    }
}

Related

  1. secondsToEndOfDay(Date aDate)
  2. setEndDay(Date date)
  3. setTimeToEndofDay(Calendar calendar)
  4. setTimeToEndOfDay(Date date)
  5. subtractSecond(Date startDate, Date endDate)
  6. toDayInterval(Date startDate, Date endDate)
  7. todayOnOrBetween(Date startDate, Date endDate)
  8. yearsBetween(final Date startDate, final Date endDate)