Java.util.GregorianCalendar.clone() Method

Advertisements


Description

The java.util.GregorianCalendar.clone() method creates and returns a copy of this object.

Declaration

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

public Object clone()

Parameters

  • NA

Return Value

This method returns a copy of this object.

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.util.*;

public class GregorianCalendarDemo {

   public static void main(String[] args) {

      // create a new calendar
      GregorianCalendar cal1 = 
              (GregorianCalendar) GregorianCalendar.getInstance();

      // print the current date and time
      System.out.println("" + cal1.getTime());

      // create a second calendar
      GregorianCalendar cal2 = new GregorianCalendar();

      // clone cal1 to cal2
      cal2 = (GregorianCalendar) cal1.clone();

      // print cal2
      System.out.println("" + cal2.getTime());

   }
}

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

Fri May 18 02:30:58 EEST 2012
Fri May 18 02:30:58 EEST 2012



Advertisements
Advertisements