is Date Before Today - Android java.util

Android examples for java.util:Today

Description

is Date Before Today

Demo Code

/*//from w ww .j a v  a  2s  . c om
 * Santiago Carrillo Barbosa - Android Calendar Picker
 * email: sancarbar@gmail.com
 *
 * https://github.com/sancarbar/Android-Calendar-Picker
 *
 * (C) 2013, Santiago Carrillo
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 3 of the License.
 *
 * This library 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
 * Lesser General Public License for more details.
 */
//package com.java2s;

import java.util.Calendar;

public class Main {
    private static final Calendar todayCalendar = Calendar.getInstance();

    public static boolean isDateBeforeToday(Calendar calendar) {
        Calendar validationCalendar = Calendar.getInstance();
        validationCalendar.setTime(calendar.getTime());
        validationCalendar.set(Calendar.MILLISECOND,
                todayCalendar.get(Calendar.MILLISECOND));
        validationCalendar.set(Calendar.SECOND,
                todayCalendar.get(Calendar.SECOND));
        validationCalendar.set(Calendar.MINUTE,
                todayCalendar.get(Calendar.MINUTE));
        validationCalendar.set(Calendar.HOUR_OF_DAY,
                todayCalendar.get(Calendar.HOUR_OF_DAY));
        return validationCalendar.getTime().before(todayCalendar.getTime());
    }
}

Related Tutorials