Java Date Start getStartOfDate(final Date date)

Here you can find the source of getStartOfDate(final Date date)

Description

Get start of date.

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

the start of date

Declaration

public static Date getStartOfDate(final Date date) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*from ww w  . ja  v  a 2  s .c  o  m*/
     * milliseconds in a second.
     */
    public static final long SECOND = 1000;
    /**
     * milliseconds in a minute.
     */
    public static final long MINUTE = SECOND * 60;

    /**
     * Get start of date.
     * 
     * @param date
     * @see Date
     * @return the start of date
     */
    public static Date getStartOfDate(final Date date) {
        if (date == null)
            return null;
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(date);

        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        return new Date(cal.getTime().getTime());
    }
}

Related

  1. getStartDate(String date)
  2. getStartDateOfCurrentSemester()
  3. getStartDateOfCurrMonth()
  4. getStartDay(Date date)
  5. getStartDayOfNextMonth(Date date)
  6. getStartOfDay(Date date)
  7. getStartOfDay(Date date)
  8. getStartOfDay(Date day)
  9. getStartOfDay(Date day)