Java Date Set setTimeZero(Date dt)

Here you can find the source of setTimeZero(Date dt)

Description

Set the time to zero 00:00:00

License

Open Source License

Parameter

Parameter Description
dt a parameter

Declaration

public static Date setTimeZero(Date dt) 

Method Source Code


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

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

public class Main {
    /**//  ww  w . j  av a  2 s.c  om
     * Set the time to zero 00:00:00
     * @param dt
     * @return
     */
    public static Date setTimeZero(Date dt) {
        if (dt == null)
            return null;
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dt);
        gc.set(Calendar.HOUR_OF_DAY, 0);
        gc.set(Calendar.MINUTE, 0);
        gc.set(Calendar.SECOND, 0);
        gc.set(Calendar.MILLISECOND, 0);
        return gc.getTime();
    }
}

Related

  1. setTime(final Date date, final int hours, final int minutes, final int seconds)
  2. setTimeForDate(Date date, int h, int m, int s)
  3. setTimePart(Date date, String time, Integer milliseconds)
  4. setTimeToNull(Date date)
  5. setTimeToZero(final Date date)
  6. setToDayStartTime(Date date)
  7. setToLastDayInMonth(final Date date)
  8. setToMidnight(Date d)
  9. setYear(Date d, int year)