Example usage for java.util GregorianCalendar equals

List of usage examples for java.util GregorianCalendar equals

Introduction

In this page you can find the example usage for java.util GregorianCalendar equals.

Prototype

@Override
public boolean equals(Object obj) 

Source Link

Document

Compares this GregorianCalendar to the specified Object.

Usage

From source file:Main.java

public static void main(String[] args) {

    GregorianCalendar cal1 = (GregorianCalendar) GregorianCalendar.getInstance();

    // create a second calendar equal to first one
    GregorianCalendar cal2 = (GregorianCalendar) (Calendar) cal1.clone();

    // print cal2
    System.out.println(cal2.getTime());

    // compare the two calendars
    System.out.println("Cal1 and Cal2 are equal:" + cal1.equals(cal2));

    // change cal 2 a bit
    cal2.add(GregorianCalendar.YEAR, 5);

    // compare the two calendars
    System.out.println("Cal1 and Cal2 are equal:" + cal1.equals(cal2));

}