1

How can I compare Calendar in Java? I want check if now_2is newer then now_1 like this:

    Calendar now_1 = Calendar.getInstance();
    sleep(10000); //sleep for 10 second
    Calendar now_2 = Calendar.getInstance();

    if(now_2.isNewer(now_1)){
        //BIG FAIL
    }
croudouu
  • 29
  • 7

1 Answers1

2

You can use

Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.compareTo(c2);

Return:

  • Value less than 0: c1 is before the c2
  • Value greater than 0: c1 is after the c2.

Please check and vote this answer.

Community
  • 1
  • 1
JoGe
  • 812
  • 9
  • 23