java.util.Calendar getWeekYear()

Description :

This java tutorial shows how to use the getWeekYear() method of Calendar class of java.util package. This method returns the week year represented by this Calendar. The week year is in sync with the week cycle. The first day of the first week is the first day of the week year.

Method Syntax :

public int getWeekYear()

Parameter Input :

 

DataType Parameter Description
N/A N/A N/A

 

Method Returns :

This method returns the week year of this Calendar.

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 getWeekYear() method of Calendar class.

package com.javatutorialhq.java.examples;

import java.util.Calendar;

/*
 * This example source code demonstrates the use of  
 * getWeekYear() method of Calendar class
 */

public class CalendarGetWeekYearExample {

	public static void main(String[] args) {

		Calendar cal = Calendar.getInstance();
		System.out.println("Time:" + cal.getTime());
		Integer result = cal.getWeekYear();
		System.out.println("Weak Year:"+result);

	}
}

Sample Output :

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

Calendar getWeekYear() method example

Calendar getWeekYear() method example

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :