GregorianCalendar class clone() method example
Creates and returns a copy of this object.
GregorianCalendarclass clone() method example. This example shows you how to use clone() method.This method Creates and returns a copy of this object.
Here is the code:-
/**
* @Program Creates and returns a copy of this object.
* Clone.java
* Author:-RoseIndia Team
* Date:-27-May-2008
*/
import java.util.*;
public class Clone {
public static void main(String[] args) {
//Creating a Calendar
GregorianCalendar g=new GregorianCalendar();
//Displaying the Current calendar
System.out.println("Current calendar is: "+g.getTime());
GregorianCalendar g1=(GregorianCalendar)g.clone();
System.out.println("Copy of the Current calendar is: "+g1.getTime());
}
} |
Output of the program:-
Current calendar is: Tue May 27 17:28:55 IST 2008
Copy of the Current calendar is: Tue May 27 17:28:55 IST 2008 |
|