Java Date Time - Java Calendar.clone()








Syntax

Calendar.clone() has the following syntax.

public Object clone()

Example

In the following code shows how to use Calendar.clone() method.

//  w w w  .java2  s. c  o  m


import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {

   public static void main(String[] args) {

      Calendar cal = new GregorianCalendar(2013, 05, 20);

      System.out.println("Past calendar : " + cal.getTime());
      
      // create a clone of first cal
      Calendar cal2 = (Calendar) cal.clone();
      
      System.out.println("Cloned calendar : " + cal2.getTime());
   }
}

The code above generates the following result.