.setMinimalDaysInFirstWeek()

Anonymous contributor's avatar
Anonymous contributor
Published Sep 10, 2023Updated May 15, 2024
Contribute to Docs

The .setMinimalDaysInFirstWeek() method of the Calendar class sets the minimal number of days required in the first week of a year based on the amount of days passed as an argument to the method.

Syntax

calendar.setMinimalDaysInFirstWeek(int day)

This method takes only one argument, int day, which is an integer constant representing the number of days which will be set as the minimal days required in the first week of the year.

Example

In the following example, .setMinimalDaysInFirstWeek() is used to set the minimal days required in the first week of the year.

import java.util.Calendar;
public class calendarSetMinimalDaysInFirstWeekExample {
public static void main(String[] args) {
// Create a calendar instance
Calendar cal = Calendar.getInstance();
// Set the minimal days required in the first week
int day = 2;
cal.setMinimalDaysInFirstWeek(day);
// Print the minimal number of days required in the first week
int min = cal.getMinimalDaysInFirstWeek();
System.out.println("Minimal Days in Week: " + min);
}
}

The output of the above code will be:

Minimal Days in Week: 2

All contributors

Contribute to Docs

Learn Java on Codecademy