Java Calendar Day truncateDay(Calendar calendar)

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

Description

Truncate the calendar's Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND to ZERO.

License

Apache License

Parameter

Parameter Description
calendar a parameter

Declaration

public static Calendar truncateDay(Calendar calendar) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

public class Main {
    /**//from w  w w  .j  ava2 s .  c o  m
     * Truncate the calendar's Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND to ZERO.
     * 
     * @param calendar
     * @return
     */
    public static Calendar truncateDay(Calendar calendar) {
        if (calendar == null) {
            throw new IllegalArgumentException("input is null");
        }
        calendar.set(Calendar.AM_PM, Calendar.AM);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar;
    }
}

Related

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