Java Date Clear clearTime(Date date)

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

Description

clear Time

License

Open Source License

Declaration

public static Date clearTime(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 {

    public static Date clearTime(Date date) {
        Calendar calendar = getCalendarFromDate(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }/*w  w w.  ja  v a  2  s.c  o  m*/

    /**
     * get calendar from date
     *
     * @param date the passing date
     * @return the calendar instance
     */
    public static Calendar getCalendarFromDate(Date date) {
        Calendar calendar = getDefaultCalendar();
        calendar.setTime(date);
        return calendar;
    }

    /**
     * get the default calendar
     *
     * @return the calendar instance
     */
    public static Calendar getDefaultCalendar() {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        return calendar;
    }
}

Related

  1. clearDate(Date date)
  2. clearDate(Date dateTime)
  3. clearDate(final Date date)
  4. clearDisplayFileCreationDateCache(final String absolutePath)
  5. clearHourMinute(Date date)
  6. clearTime(Date date)
  7. clearTime(GregorianCalendar date)
  8. clearTimeComponent(Date date)