Java .getWeekYear()
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.
Syntax
calendar.getWeekYear()
Returns the week year represented by this Calendar object in as an integer.
Example
This example code shows the basic use of the .getWeekYear() method:
import java.util.Calendar;// CalendarGetWeekYearExample.javapublic class CalendarGetWeekYearExample{public static void main(String[] args) {// Create a Calendar instanceCalendar calendar = Calendar.getInstance();// Get the current time in weekyearlong currentWeekYear = calendar.getWeekYear();// Prints current time in week yearSystem.out.println("Current Week Year: " + currentWeekYear);}}
The output should be similar to:
Current Week Year: 2023
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
- Beginner Friendly.17 hours