Java Utility Library

Java Calendar - getWeeksInWeekYear() Method



The java.util.Calendar.getWeeksInWeekYear() method returns the number of weeks in the week year represented by this Calendar.

Syntax

public int getWeeksInWeekYear()

Parameters

No parameter is required.

Return Value

Returns the number of weeks in the week year.

Exception

Throws UnsupportedOperationException, if any week year numbering isn't supported in this Calendar.

Example:

In the example below, the java.util.Calendar.getWeeksInWeekYear() method returns the number of weeks in the week year represented by the given Calendar.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Calendar object with specified date
    Calendar Cal = new GregorianCalendar(2015, 10, 25);

    //printing the Calendar
    System.out.println("The Calendar is: " + Cal.getTime());

    //printing the number of weeks in the specified Calendar
    int week = Cal.getWeeksInWeekYear();
    System.out.println("Number of weeks: " + week);
  }
}

The output of the above code will be:

The Calendar is: Wed Nov 25 00:00:00 UTC 2015
Number of weeks: 52

❮ Java.util - Calendar