Java Date Time - Java Date.clone()








Syntax

Date.clone() has the following syntax.

public Object clone()

Example

In the following code shows how to use Date.clone() method.

//ww  w  .  ja v  a  2  s  . c o  m

import java.util.Date;

public class Main {

   public static void main(String[] args) {

      // create a date
      Date date = new Date();

      // clone it to a second date
      Object date2 = date.clone();

      // print the results
      System.out.println("Original Date:" + date.toString());
      System.out.println("Cloned date :" + date2.toString());
   }
}

The code above generates the following result.