compare date value in calendar With Today - Android java.util

Android examples for java.util:Day

Description

compare date value in calendar With Today

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main{

    /**//from w w w . j  a v  a  2s.c om
     * Compares the day represented by this {@code Calendar} to one that repersents today
     * 
     * @param p_cal
     *        the object to compare to this instance.
     * @return 0 if the days of the two {@code Calendar}s are equal, -1 if the day of this {@code Calendar} is before
     *         the today, 1 if the day of this {@code Calendar} is after today.
     */
    public static Integer compareWithToday(Calendar p_cal) {
        Calendar comparer = (Calendar) m_today.clone();
        comparer.set(Calendar.YEAR, p_cal.get(Calendar.YEAR));
        comparer.set(Calendar.MONTH, p_cal.get(Calendar.MONTH));
        comparer.set(Calendar.DAY_OF_MONTH,
                p_cal.get(Calendar.DAY_OF_MONTH));

        Integer retVal = comparer.compareTo(m_today);
        return retVal;
    }

}

Related Tutorials