Java Calendar - getWeekYear() Method
The java.util.Calendar.getWeekYear() method returns the week year represented by this Calendar.
Syntax
public int getWeekYear()
Parameters
No parameter is required.
Return Value
Returns the week year represented by this Calendar.
Exception
Throws UnsupportedOperationException, if any week year numbering isn't supported in this Calendar.
Example:
In the example below, the java.util.Calendar.getWeekYear() method returns the week year represented by the given Calendar object.
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 week year of the specified Calendar int weekyear = Cal.getWeekYear(); System.out.println("Week Year: " + weekyear); //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 Week Year: 2015 Number of weeks: 52
❮ Java.util - Calendar