Java.util.Calendar.clone() Method



Description

The java.util.Calendar.clone() returns a shallow copy of this Calendar object.

Declaration

Following is the declaration for java.util.Calendar.clone() method

public Object clone()

Parameters

NA

Return Value

This method does not return any value.

Exception

NA

Example

The following example shows the usage of java.util.Calendar.clone() method.

package com.tutorialspoint;

import java.util.*;

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

      // create new calendar at specific date.
      Calendar cal = new GregorianCalendar(2008, 05, 20);

      // print date for default value
      System.out.println("Past calendar : " + cal.getTime());

      // create a clone of first cal
      Calendar cal2 = (Calendar) cal.clone();

      // display the copy
      System.out.println("Cloned calendar : " + cal2.getTime());
   }
}

Let us compile and run the above program, this will produce the following result −

Past calendar : Fri Jun 20 00:00:00 EEST 2008
Cloned calendar : Fri Jun 20 00:00:00 EEST 2008
java_util_calendar.htm
Advertisements