Java Utility Library

Java Calendar - setMinimalDaysInFirstWeek() Method



The java.util.Calendar.setMinimalDaysInFirstWeek() method is used to set what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call this method with value 1. If it must be a full week, use value 7.

Syntax

public void setMinimalDaysInFirstWeek(int value)

Parameters

value Specify the given minimal days required in the first week of the year.

Return Value

void type.

Exception

NA

Example:

In the example below, the java.util.Calendar.setMinimalDaysInFirstWeek() method is used to set the minimal days required in the first week of the year.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating Calendar objects
    Calendar Cal = Calendar.getInstance(Locale.US);

    //printing the first day of the week
    System.out.println("Minimum days required in US: " + 
                        Cal.getMinimalDaysInFirstWeek());

    //set the minimal days required in the first week 
    Cal.setMinimalDaysInFirstWeek(7);

    //printing the first day of the week
    System.out.println("Minimum days required in US: " + 
                        Cal.getMinimalDaysInFirstWeek()); 
  }
}

The output of the above code will be:

Minimum days required in US: 1
Minimum days required in US: 7

❮ Java.util - Calendar