Java Day Start startOfDay(Date dateInst)

Here you can find the source of startOfDay(Date dateInst)

Description

Method to return a "normalized" version of the input Date whose time is reset to the absolute start of that same day (first millisecond of first second of first minute of first hour).

License

Open Source License

Parameter

Parameter Description
dateInst - instance of Date

Return

- instance of Date as described

Declaration

public static Date startOfDay(Date dateInst) 

Method Source Code

//package com.java2s;
/*/*from  w w w.jav a2s .  com*/
    
 Copyright IBM Corp. 2012, 2016
 This file is part of Anomaly Detection Engine for Linux Logs (ADE).

 ADE is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 ADE is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ADE.  If not, see <http://www.gnu.org/licenses/>.
    
 */

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

public class Main {
    /**
     * Method to return a "normalized" version of the input Date
     * whose time is reset to the absolute start of that same day
     * (first millisecond of first second of first minute of first hour).
     *    
     * @param dateInst - instance of Date
     * @return - instance of Date as described
     */
    public static Date startOfDay(Date dateInst) {

        if (dateInst == null) {
            throw new IllegalArgumentException();
        }
        final Calendar cal = new GregorianCalendar();
        cal.setTime(dateInst);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();

    }
}

Related

  1. startOfDay(Date aDate)
  2. startOfDay(Date aDate)
  3. startOfDay(Date date)
  4. startOfDay(Date date)
  5. startOfDay(Date inDate, TimeZone timeZone)
  6. startOfDay(Date value)
  7. startOfDay(final Date date)
  8. startOfDay(final Date date)