Java Date Set stripTime(Date date)

Here you can find the source of stripTime(Date date)

Description

Returns a Date object representing 00:00:00AM of the input date.

License

Open Source License

Parameter

Parameter Description
date input

Return

a Date object containing Time part as 00:00:00.000 AM.

Declaration

public static Date stripTime(Date date) 

Method Source Code

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

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

public class Main {
    /**//from www. j a  v a2 s .c om
     * Returns a Date object representing 00:00:00AM of the input date.
     * 
     * @param date input
     * @return a Date object containing Time part as 00:00:00.000 AM.
     */
    public static Date stripTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        Calendar copy = Calendar.getInstance();
        copy.setTime(date);
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE));
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
        return calendar.getTime();
    }
}

Related

  1. setToLastDayInMonth(final Date date)
  2. setToMidnight(Date d)
  3. setYear(Date d, int year)
  4. setYear(Date date, int year)
  5. stripTime(Date d)
  6. stripTime(Date date)
  7. stripTime(Date time)
  8. stripTimeFromDate(Date aDate)