.clone()
Anonymous contributor
Published Aug 16, 2023
Contribute to Docs
The .clone()
method of the Calendar
class is used to return a copy of a Calendar object.
Syntax
result = myCalendar.clone()
Returns a copy of the myCalendar
Calendar
object.
Example
This example creates a calendar, displays it, clones it and displays its clone.
import java.util.*;public class CalendarCloneExample {public static void main(String args[]){// Create a calendar objectCalendar original_calendar = new GregorianCalendar(1971, 8, 13);// Print original calendarSystem.out.println(original_calendar.getTime());// Cloning the originalCalendar copy_calendar = (Calendar) original_calendar.clone();// Print copy calendarSystem.out.println(copy_calendar.getTime());}}
Output for the above code will be:
Mon Sep 13 00:00:00 UTC 1971Mon Sep 13 00:00:00 UTC 1971
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.