Java Calendar getMinimalDaysInFirstWeek() Method



Description

The Java Calendar getMinimalDaysInFirstWeek() method gets the minimal days required in the first week of the year needed.

Declaration

Following is the declaration for java.util.Calendar.getMinimalDaysInFirstWeek() method

public int getMinimalDaysInFirstWeek()

Parameters

NA

Return Value

The method returns the minimal days required in the first week of the year.

Exception

NA

Getting Minimum Days in First Week from a Current Dated Calendar Instance Example

The following example shows the usage of Java Calendar getMinimalDaysInFirstWeek() method. We're creating an instance of a Calendar of current date using getInstance() method and printing the minimum days in first week of the year using getMinimalDaysInFirstWeek().

package com.tutorialspoint;

import java.util.Calendar;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create a calendar    
      Calendar cal = Calendar.getInstance();

      // minimum days in first week of the year.
      System.out.print(cal.getMinimalDaysInFirstWeek());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

1

Getting Minimum Days in First Week from a Given Dated Calendar Instance Example

The following example shows the usage of Java Calendar getMinimalDaysInFirstWeek() method. We're creating an instance of a Calendar of current date using getInstance() method. Then we've updated the year and printing the minimum days in first week of the year using getMinimalDaysInFirstWeek().

package com.tutorialspoint;

import java.util.Calendar;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create a calendar    
      Calendar cal = Calendar.getInstance();

      cal.set(Calendar.YEAR, 2021);

      // minimum days in first week of the year.
      System.out.print(cal.getMinimalDaysInFirstWeek());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

1

Getting Minimum Days in First Week from a Given Dated Calendar Instance Example

The following example shows the usage of Java Calendar getMinimalDaysInFirstWeek() method. We're creating an instance of a Calendar of current date using getInstance() method. Then we've updated the year and printing the minimum days in first week of the year using getMinimalDaysInFirstWeek().

package com.tutorialspoint;

import java.util.Calendar;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create a calendar    
      Calendar cal = Calendar.getInstance();

      cal.set(Calendar.YEAR, 2020);

      // minimum days in first week of the year.
      System.out.print(cal.getMinimalDaysInFirstWeek());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

1
Advertisements