Java Utility Library

Java Date - clone() Method



The java.util.Date.clone() method returns a copy of the given date object.

Syntax

public Object clone()

Parameters

No parameter is required.

Return Value

Returns a copy of the given date object.

Exception

NA

Example:

In the example below, the java.util.Date.clone() method is used to create a copy of the given date object.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Date
    Date Dt1 = new Date();

    //printing Date
    System.out.println("Original Date: " + Dt1);

    //creating a clone of the date
    Object Dt2 = Dt1.clone();

    //printing Date
    System.out.println("Cloned Date: " + Dt2);
  }
}

The output of the above code will be:

Original Date: Wed Nov 25 00:00:00 GMT 1998
Cloned Date: Wed Nov 25 00:00:00 GMT 1998

❮ Java.util - Date