Java.util.GregorianCalendar.equals() 方法


Java.util.GregorianCalendar.equals() 方法

package com.codingdict;

import java.util.*;

public class GregorianCalendarDemo {
   public static void main(String[] args) {

      // create a new calendar
      GregorianCalendar cal1 = (GregorianCalendar) GregorianCalendar.getInstance();

      // print the current date and time
      System.out.println("" + cal1.getTime());

      // 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));
   }
}