Java Calendar Day getEndOfDay(Calendar c)

Here you can find the source of getEndOfDay(Calendar c)

Description

Gets the end of the day based on the given Calendar .

License

Open Source License

Parameter

Parameter Description
c Calendar for which to get the end of the day

Return

The end of the day for the given

Declaration

public static Calendar getEndOfDay(Calendar c) 

Method Source Code


//package com.java2s;
/*/*from  ww  w .ja  v a2 s. c om*/
 *  Copyright (C) 2010 - 2014 Converge Consulting Limited
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Gets the end of the day based on the given {@link Calendar}.
     *
     * @param c Calendar for which to get the end of the day
     * @return The end of the day for the given {@link Calendar}
     */
    public static Calendar getEndOfDay(Calendar c) {
        Calendar result = (Calendar) c.clone();
        result.set(Calendar.HOUR_OF_DAY, 23);
        result.set(Calendar.MINUTE, 59);
        result.set(Calendar.SECOND, 59);
        result.set(Calendar.MILLISECOND, 999);
        return result;
    }

    /**
     * Gets the end of the day based on the given {@link Date}.
     *
     * @param d Date for which to get the end of the day
     * @return The end of the day for the given {@link Date}
     */
    public static Calendar getEndOfDay(Date d) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        return getEndOfDay(c);
    }
}

Related

  1. getDaysFromThen(Calendar aDate)
  2. getDayStr(Calendar cal)
  3. getDayString(Calendar cal1)
  4. getDayStringByCalendar(Calendar calendar)
  5. getEndDay(Calendar cal)
  6. getEndOfDay(Date date, Calendar cal)
  7. getEndOfTodayAsCalendar()
  8. getFirstDay(Calendar cal)
  9. getGregorianDay(Calendar cal)