java.util.Calendar getWeeksInWeekYear()

Description :

This java tutorial shows how to use the getWeeksInWeekYear() method of Calendar class of java.util package. This method returns the number of weeks in the week year represented by the Calendar object.

Method Syntax :

public int getWeeksInWeekYear()

Parameter Input :


DataType Parameter Description


Method Returns :

This method returns the number of weeks in the week year.

Compatibility Version :

Requires Java 1.7 and up

Exception :

UnsupportedOperationException – if any week year numbering isn’t supported in this Calendar.

Java Code Example :

This java example source code demonstrates the use of getWeeksInWeekYear() method of Calendar class. The default week year in a week year is equal to 52 not unless this Calendar object has been overridden. You might be wondering in a real life scenario how to get this value, simple one week is 7 days and in a year we have 365 days. By simple division 365/4 that would be 52.XX and since we are only interested in getting the number of weeks the decimal can be neglected thus the result of 52 weeks.


import java.util.Calendar;

 * This example source code demonstrates the use of  
 * getWeeksInWeekYear() of Calendar class

public class CalendarGetWeeksInWeekYearExample {

	public static void main(String[] args){

		Calendar cal = Calendar.getInstance();
		System.out.println("Time:" + cal.getTime());		
		cal.setWeekDate(1975, 37, 2);
		System.out.println("New Time:"+cal.getTime());
		System.out.println("Weeks in week year value:"
				+ cal.getWeeksInWeekYear());

Sample Output :

Running the getWeeksInWeekYear() method example source code of Calendar class will give you the following output:

Calendar getWeeksInWeekYear() method example

Calendar getWeeksInWeekYear() method example

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :