Java Calendar Time clearTime(final Calendar c)

Here you can find the source of clearTime(final Calendar c)

Description

Set Calendar#HOUR_OF_DAY , Calendar#MINUTE , Calendar#SECOND and Calendar#MILLISECOND to 0.

License

Open Source License

Parameter

Parameter Description
c the Calendar .

Declaration

public static void clearTime(final Calendar c) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013, 2014, 2015 QPark Consulting  S.a r.l.
 * /*www .j a  va  2s .com*/
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0. 
 * The Eclipse Public License is available at 
 * http://www.eclipse.org/legal/epl-v10.html.
 ******************************************************************************/

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

public class Main {
    /**
     * Set {@link Calendar#HOUR_OF_DAY}, {@link Calendar#MINUTE},
     * {@link Calendar#SECOND} and {@link Calendar#MILLISECOND} to
     * <code>0</code>.
     * 
     * @param c
     *            the {@link Calendar}.
     */
    public static void clearTime(final Calendar c) {
        if (c != null) {
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);
        }
    }

    /**
     * Returns a date with hour, minute, second and millisecond set to
     * <code>0</code>.
     * 
     * @param d
     *            the {@link Date} with hour, minute, second and millisecond
     *            set.
     * @return the {@link Date} with cleared time.
     */
    public static Date clearTime(final Date d) {
        if (d != null) {
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            clearTime(c);
            return c.getTime();
        } else {
            return d;
        }
    }
}

Related

  1. clearCalendarTimeParts(Calendar cal)
  2. clearTime(Calendar c)
  3. clearTime(Calendar cal)
  4. clearTime(Calendar cal)
  5. clearTime(Calendar calendar)
  6. clearTimeFields(final Calendar calendar)
  7. clearTimeFields(Set c)
  8. clearTimeFromCalendar(Calendar calendar)
  9. compareTimeOnly(Calendar cal1, Calendar cal2)