compare two Calendar date - Android java.util

Android examples for java.util:Calendar

Description

compare two Calendar date

Demo Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main{

    public static int compare(Calendar d1, Calendar d2) {
        int result = 0;

        if (d1 == null && d2 == null)
            return result;
        if (d1 == null)
            return -1;
        if (d2 == null)
            return 1;

        if (d1.after(d2))
            result = 1;//from   w  w  w .j ava2s  . c  o m
        else if (d1.before(d2))
            result = -1;
        else
            result = 0;

        return result;
    }

}

Related Tutorials