Java.util.Date.clone() Method

Advertisements


Description

The java.util.Date.clone() returns a shallow copy of this Date object.

Declaration

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

public Object clone()

Parameters

  • NA

Return Value

This method does not return any value.

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.util.*;

public class DateDemo {

   public static void main(String[] args) {

      // create a date
      Date date = new Date(98, 5, 21);

      // 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());
   }
}

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

Original Date:Sun Jun 21 00:00:00 EEST 1998
Cloned date :Sun Jun 21 00:00:00 EEST 1998



Advertisements
Advertisements