Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Before Method in Java Calendar To Compare Date and Time in Java

  1. import java.util.Calendar;
  2. public classBeforeMethod {
  3. public static void main(String[] args) {
  4. //create first Calendar object
  5. Calendar old = Calendar.getInstance();
  6. //set it to some old date
  7. old.set(Calendar.YEAR, 1990);
  8. //create second Calendar object
  9. Calendar now = Calendar.getInstance();
  10. /*
  11. * To compare two different Calendar objects, use
  12. * boolean before(Caledar anotherCal) method.
  13. *
  14. * If the first Calendar object's date and time is before
  15. * anotherCal date and time,
  16. * it returns true, false otherwise.
  17. */
  18. System.out.println("Is old before now ? : " + old.before(now));
  19. }
  20. }