compare Two Date - Java java.util

Java examples for java.util:Date Compare

Description

compare Two Date

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Date beforeDate = new Date();
        Date afterDate = new Date();
        System.out.println(compareTwoDate(beforeDate, afterDate));
    }/*from  w  ww.  j  a  v a2  s  . c o  m*/

    /**
     * 
     * @param beforeDate
     * @param afterDate
     * @return
     */
    public static boolean compareTwoDate(Date beforeDate, Date afterDate) {
        if (beforeDate == null && afterDate == null) {
            return false;
        }
        Calendar beforeCalendar = Calendar.getInstance();
        beforeCalendar.setTime(beforeDate);
        Calendar afterCalendar = Calendar.getInstance();
        afterCalendar.setTime(afterDate);
        return (afterCalendar.compareTo(beforeCalendar) > 0);
    }
}

Related Tutorials