Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Sep 12, 2023
Contribute to Docs

The .getWeekYear() method of the Calendar class returns the time represented by a Calendar object in the form of the week year.



Returns the week year represented by this Calendar object in as an integer.


This example code shows the basic use of the .getWeekYear() method:

import java.util.Calendar;
// CalendarGetWeekYearExample.java
public class CalendarGetWeekYearExample{
public static void main(String[] args) {
// Create a Calendar instance
Calendar calendar = Calendar.getInstance();
// Get the current time in weekyear
long currentWeekYear = calendar.getWeekYear();
// Prints current time in week year
System.out.println("Current Week Year: " + currentWeekYear);

The output should be similar to:

Current Week Year: 2023

All contributors

Looking to contribute?

Learn Java on Codecademy