Java Calendar Time stripTimeComponent(Calendar cal)

Here you can find the source of stripTimeComponent(Calendar cal)

Description

Strips the time component from a Calendar object, leaving only the date component

License

Open Source License

Declaration

public static void stripTimeComponent(Calendar cal) 

Method Source Code

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

import java.util.Calendar;

import java.util.Date;

public class Main {
    /** /*w ww  .j  a va  2  s  .c o m*/
     * Strips the time component from a Calendar object, leaving only the date component
     */
    public static void stripTimeComponent(Calendar cal) {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
    }

    /**
     * Strips the time component of a Date object, leaving only the date component
     */
    public static void stripTimeComponent(Date date) {
        if (date == null) {
            return;
        } else {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            stripTimeComponent(cal);
            date = cal.getTime();
        }
    }
}

Related

  1. setTimeFrom(Calendar c)
  2. setTimeTo0(final Calendar calendar)
  3. setTimeToMidnight(GregorianCalendar c)
  4. setTimeToMinOrMax(Calendar cal, boolean max)
  5. stripTime(final Calendar cal)
  6. time2InicioDelDia(Calendar fecha)
  7. timestamp17ToCalendar(String timestamp17String)
  8. timestamp2Calendar(long timestamp)
  9. timestampToCalendar(String timestamp)