.complete()
Published Aug 21, 2023Updated May 15, 2024
Contribute to Docs
The .complete()
method of the Calendar
class is used to fill in any empty fields in the Calendar
instance.
Syntax
someCalendar.complete()
Note: If the time value has not been calculated from the calendar field values, the
.computeTime()
method is called. Then to calculate all calendar field values, the.computeFields()
method is called.
Example
The example below demonstrates the use of the .complete()
method.
import java.util.GregorianCalendar;public class CalendarCompleteExample extends GregorianCalendar {public static void main(String[] args) {// Create a new calendarCalendarCompleteExample cal = new CalendarCompleteExample();// Print the current dateSystem.out.println("The current date is : " + cal.getTime());// Clear the calendarcal.clear();// Set a new year and call complete()cal.set(GregorianCalendar.YEAR, 2021);cal.complete();// Print the current dateSystem.out.println("New date is : " + cal.getTime());}}
This code will return an output similar to the following;
The current date is: Mon Aug 14 15:39:33 UTC 2023The new date is: Tue Jan 01 00:00:00 UTC 2021
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.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly17 hours