Java Date Set stripTimeFromDate(Date aDate)

Here you can find the source of stripTimeFromDate(Date aDate)

Description

Strips the time information from a given Date (sets all time fields to zero).

License

Open Source License

Parameter

Parameter Description
aDate the date

Return

a new Date without time information

Declaration

public static Date stripTimeFromDate(Date aDate) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

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

public class Main {
    /**/*  w  w  w  .j  a  va2  s.co  m*/
     * Strips the time information from a given {@link Date} (sets all time fields to zero).
     * 
     * @param aDate
     *            the date
     * @return a new Date without time information
     */
    public static Date stripTimeFromDate(Date aDate) {
        Calendar tempCalendar = Calendar.getInstance();

        tempCalendar.setTime(aDate);
        tempCalendar.set(Calendar.HOUR_OF_DAY, 0);
        tempCalendar.set(Calendar.MINUTE, 0);
        tempCalendar.set(Calendar.SECOND, 0);
        tempCalendar.set(Calendar.MILLISECOND, 0);

        return tempCalendar.getTime();
    }
}

Related

  1. setYear(Date date, int year)
  2. stripTime(Date d)
  3. stripTime(Date date)
  4. stripTime(Date date)
  5. stripTime(Date time)