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.


//  ww w.j  a  v a  2s . c om


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.