Date clone() method in Java with Examples Last Updated : 01 Nov, 2020 Comments Improve Suggest changes Like Article Like Report The clone() method of Date class in Java returns the duplicate of the passed Date object. This duplicate is just a shallow copy of the given Date object.Syntax: public Object clone() Parameters: The method does not accept any parameters.Return Value: The method returns a clone of the object.Below programs illustrate the use of clone() Method:Example 1: Java // Java code to demonstrate // clone() method of Date class import java.util.Date; import java.util.Calendar; public class GfG { public static void main(String args[]) { // Creating a Calendar object Calendar c1 = Calendar.getInstance(); // Set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 11); // Set Date c1.set(Calendar.DATE, 05); // Set Year c1.set(Calendar.YEAR, 1996); // Creating a date object // with specified time. Date dateOne = c1.getTime(); Object dateTwo = dateOne.clone(); System.out.println("Original Date: " + dateOne.toString()); System.out.println("Cloned Date: " + dateTwo.toString()); } } Output: Original Date: Thu Dec 05 05:39:04 UTC 1996 Cloned Date: Thu Dec 05 05:39:04 UTC 1996 Example 2: Java // Java code to demonstrate // clone() method of Date class import java.util.Date; import java.util.Calendar; public class GfG { public static void main(String args[]) { // Creating a Calendar object Calendar c1 = Calendar.getInstance(); // Set Month // MONTH starts with 0 i.e. ( 0 - Jan) c1.set(Calendar.MONTH, 00); // Set Date c1.set(Calendar.DATE, 30); // Set Year c1.set(Calendar.YEAR, 2019); // Creating a date object // with specified time. Date dateOne = c1.getTime(); Object dateTwo = dateOne.clone(); System.out.println("Original Date: " + dateOne.toString()); System.out.println("Cloned Date: " + dateTwo.toString()); } } Output: Original Date: Wed Jan 30 05:39:10 UTC 2019 Cloned Date: Wed Jan 30 05:39:10 UTC 2019 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#clone-- Comment More infoAdvertise with us Next Article Date clone() method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-util-Date +1 More Practice Tags : JavaMisc Similar Reads Date before() method in Java with Examples The before() method of Java Date class tests whether the date is before the specified date or not. Syntax: public boolean before(Date when) Parameters: The function accepts a single parameter when which specifies the date that has to be checked. Return Value: It returns a Boolean value. It will retu 2 min read Date compareTo() method in Java with examples The compareTo() method of Java Date class compares two dates and sort them for order. Syntax: public int compareTo(Date anotherDate) Parameters: The function accepts a single parameter anotherDate which specifies the date to be compared . Return Value: The function gives three return values specifie 2 min read util.date class methods in Java with Examples Following are some important date class methods : .toString() : java.util.Date.tostring() method is a java.util.Date class method.It displays the Current date and time. Here Date object is converted to a string and represented as: day mon dd hh:mm:ss zz yyyy day : day of the week mon : month dd : da 5 min read Date from() method in Java with Examples The from(Instant inst) method of Java Date class returns an instance of date which is obtained from an Instant object. Syntax: public static Date from(Instant inst) Parameters: The method takes one parameter inst of Instant type which is required to be converted. Return Value: The method returns a d 2 min read Calendar add() Method in Java with Examples The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the 3 min read Like