.clone()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jul 31, 2023
Contribute to Docs

The Date.clone() method returns a copy or duplicate of a specified Date object.

Syntax

currentDate.clone()

The Date.clone() method does not take any parameters.

It returns a copy or duplicate of the currentDate, and the returned value is an Object, not a Date.

Example

The following example shows an implementation of Date.clone():

import java.util.Date;
public class Main {
public static void main(String[] args) {
Date currentDate = new Date();
System.out.println("The original date is " + currentDate);
System.out.println("The clone of the date is " + currentDate.clone());
}
}

The output will be similar to:

The original date is Wed Jul 26 06:47:06 GMT 2023
The clone of the date is Wed Jul 26 06:47:06 GMT 2023

All contributors

Looking to contribute?

Learn Java on Codecademy