Java Calendar Day endOfDay(Calendar calendar)

Here you can find the source of endOfDay(Calendar calendar)

Description

Adjust the given calendar to the last millisecond of the specified date.

License

Open Source License

Parameter

Parameter Description
calendar calendar to adjust.

Declaration

public static void endOfDay(Calendar calendar) 

Method Source Code

//package com.java2s;
/*//from  w  w w  . jav  a 2s .  c  om
 * #%L
 * The AIBench Plugin Manager Plugin
 * %%
 * Copyright (C) 2006 - 2016 Daniel Glez-Pe?a and Florentino Fdez-Riverola
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser 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 Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
 * #L%
 */

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

public class Main {
    /**
     * Adjust the given calendar to the last millisecond of the given date.
     * that is all time fields cleared. The Date of the adjusted Calendar is
     * returned. 
     * 
     * @param calendar calendar to adjust.
     * @param date the Date to use.
     * @return the end of the day of the given date
     */
    public static Date endOfDay(Calendar calendar, Date date) {
        calendar.setTime(date);
        endOfDay(calendar);
        return calendar.getTime();
    }

    /**
     * Adjust the given calendar to the last millisecond of the specified date.
     * 
     * @param calendar calendar to adjust.
     */
    public static void endOfDay(Calendar calendar) {
        calendar.add(Calendar.DATE, 1);
        startOfDay(calendar);
        calendar.add(Calendar.MILLISECOND, -1);
    }

    /**
     * Adjust the given calendar to the first millisecond of the given date.
     * that is all time fields cleared. The Date of the adjusted Calendar is
     * returned. 
     * 
     * @param calendar calendar to adjust.
     * @param date the Date to use.
     * @return the start of the day of the given date
     */
    public static Date startOfDay(Calendar calendar, Date date) {
        calendar.setTime(date);
        startOfDay(calendar);
        return calendar.getTime();
    }

    /**
     * Adjust the given calendar to the first millisecond of the current day.
     * that is all time fields cleared.
     * 
     * @param calendar calendar to adjust.
     */
    public static void startOfDay(Calendar calendar) {
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
    }
}

Related

  1. daysFromBinStart(Calendar date)
  2. daysSinceTheJesus(Calendar cal)
  3. dayStart(Calendar date)
  4. dayStart(final Calendar cal)
  5. decreaseByDay(final Calendar calendar)
  6. getAge(Calendar dateOfBirth, Calendar onThisDay)
  7. getBeginDay(Calendar cal)
  8. getCanonicalDay(Calendar cal)
  9. getCanonicalDayFrom(Calendar day, int daysFrom)