Java Calendar Day trimToDay(Calendar calendar)

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

Description

Trims the specified calendar to the day by resetting the following attributes:
  • hour of day
  • minutes
  • seconds
  • milliseconds
The passed calendar is not modified by this method.

License

MIT License

Parameter

Parameter Description
calendar a calendar to trim.

Return

the trimmed calendar.

Declaration

public static Calendar trimToDay(Calendar calendar) 

Method Source Code

//package com.java2s;
/*/* w w  w.  j av a  2 s .  co  m*/
 * Copyright (c) 2015-2016 QuartzDesk.com.
 * Licensed under the MIT license (https://opensource.org/licenses/MIT).
 */

import java.util.Calendar;

public class Main {
    /**
     * Trims the specified calendar to the day by resetting the following attributes:
     * <ul>
     * <li>hour of day</li>
     * <li>minutes</li>
     * <li>seconds</li>
     * <li>milliseconds</li>
     * </ul>
     * The passed calendar is not modified by this method.
     *
     * @param calendar a calendar to trim.
     * @return the trimmed calendar.
     */
    public static Calendar trimToDay(Calendar calendar) {
        Calendar cloneCal = (Calendar) calendar.clone();
        cloneCal.set(Calendar.HOUR_OF_DAY, 0);
        cloneCal.set(Calendar.MINUTE, 0);
        cloneCal.set(Calendar.SECOND, 0);
        cloneCal.set(Calendar.MILLISECOND, 0);

        return cloneCal;
    }
}

Related

  1. startOfDay(Calendar calendar)
  2. toCountWorkDays(GregorianCalendar start, GregorianCalendar end)
  3. todayCalendar()
  4. toEndOfDayCalendar(Date date)
  5. toNextWorkDay(Calendar cal)
  6. truncateDay(Calendar calendar)