Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Compare two Date object in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 461
    Comment on it

    Sometime we need two compare two dates like which Date object's time coming first or last.

    Here is the code to compare two dates.

        Date date1;
    Date date2;
    if(date1.before(date2)){
            System.out.println("Date 1 is before date 2");
            }
            if(date2.before(date1)){
            System.out.println("Date 2 is before date 1");
            }
            if(date1.compareTo(date2)==0)
            {
            System.out.println("both dates are equals");
            }
    

    Cheers !!!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: