Java Calendar Night setMidnight(Calendar date)

Here you can find the source of setMidnight(Calendar date)

Description

Set the time of a Calendar object to midnight by truncation.

License

Open Source License

Parameter

Parameter Description
date The Calendar object to be set to midnight

Return

A copy of the object with the time set to midnight

Declaration

@Deprecated
public static Calendar setMidnight(Calendar date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    /**//  ww  w .j  a  v  a  2s .  c o m
     * Set the time of a {@link Calendar} object to midnight by truncation.
     * This returns a new object - the original remains untouched.
     *
     * @param date The {@link Calendar} object to be set to midnight
     * @return A copy of the {@link Calendar} object with the time set to midnight
     */
    @Deprecated
    public static Calendar setMidnight(Calendar date) {
        Calendar result = (Calendar) date.clone();
        result.set(Calendar.HOUR_OF_DAY, 0);
        result.set(Calendar.MINUTE, 0);
        result.set(Calendar.SECOND, 0);
        result.set(Calendar.MILLISECOND, 0);
        return result;
    }
}

Related

  1. getMidnightCalendar()
  2. getMidnightCalendarInstance()
  3. midnightOf(Calendar cal)
  4. setMidnight(Calendar cal)
  5. setMidnight(final Calendar cal)
  6. toMidnightCalendar(Date date)