Java Calendar - clone() Method
The java.util.Calendar.clone() method returns a copy of the given calendar object.
Syntax
public Object clone()
Parameters
No parameter is required.
Return Value
Returns a copy of the given calendar object.
Exception
NA
Example:
In the example below, the java.util.Calendar.clone() method is used to create a copy of the given calendar object.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a Calendar with specified date Calendar Cal1 = new GregorianCalendar(2018, 10, 25); //Creating a date object from calendar //and printing it System.out.println("Original Calendar: " + Cal1.getTime()); //creating a clone of the calendar Calendar Cal2 = (Calendar)Cal1.clone(); //Creating a date object from cloned calendar //and printing it System.out.println("Cloned Calendar: " + Cal2.getTime()); } }
The output of the above code will be:
Original Calendar: Sun Nov 25 00:00:00 UTC 2018 Cloned Calendar: Sun Nov 25 00:00:00 UTC 2018
❮ Java.util - Calendar