.complete()
THE-Spellchecker154 total contributions
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
All contributors
- THE-Spellchecker154 total contributions
- Anonymous contributorAnonymous contributor1 total contribution
- THE-Spellchecker
- Anonymous contributor
Looking to contribute?
- 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.