Java Calendar Time removeTime(final Calendar date)

Here you can find the source of removeTime(final Calendar date)

Description

Remote the time elements of the passed Calendar , setting the time to midnight of that day.

License

Open Source License

Parameter

Parameter Description
date The date that you wish to remove the time portions from.

Return

the same istance passed, with the time fields now set to 0.

Declaration

public static Calendar removeTime(final Calendar date) 

Method Source Code


//package com.java2s;
// Licensed under the MIT license. See License.txt in the repository root.

import java.util.Calendar;

public class Main {
    /**/*from  w  w  w  .  j  a v a2 s  .c  om*/
     * Remote the time elements of the passed {@link Calendar}, setting the time
     * to midnight of that day. Note: This function will affect the date passed
     * as well as returning the same date. If you do not wish this method to
     * affect the date passed then you should clone it before passing.
     *
     * @param date
     *        The date that you wish to remove the time portions from.
     * @return the same {@link Calendar} istance passed, with the time fields
     *         now set to 0.
     */
    public static Calendar removeTime(final Calendar date) {
        date.set(Calendar.SECOND, 0);
        date.set(Calendar.MINUTE, 0);
        date.set(Calendar.HOUR, 0);
        date.set(Calendar.HOUR_OF_DAY, 0);
        date.set(Calendar.MILLISECOND, 0);

        // Note that this line is needed due to a strange issue in Gregorian
        // Calendar.
        // If this is not done then subsequent additions to the time etc can be
        // ignored.
        date.getTimeInMillis();

        return date;
    }
}

Related

  1. parseTime(Calendar calendar, String time_string)
  2. parseTime(String time, Calendar calendar)
  3. removeTime(Calendar c)
  4. removeTime(Calendar cal)
  5. removeTime(Calendar calendar)
  6. resetTime(Calendar cal)
  7. resetTime(Calendar cal)
  8. resetTime(GregorianCalendar cal)
  9. roundTime(double dt, Calendar tmp)