.getWeeksInWeekYear()
Published Sep 16, 2023
Contribute to Docs
The .getWeeksInWeekYear()
method of the Calendar
class returns an integer representing the number of weeks in a week year.
Syntax
calendar.getWeeksInWeekYear()
Note: The concept of a week-based year is important in some calendar systems, especially when dealing with fiscal years or other non-standard year definitions. The number of weeks in a week-based year can vary depending on factors such as the starting day of the week and whether the year contains partial weeks at the beginning or end.
Example 1
The example below demonstrates the use of the .getWeeksInWeekYear()
method.
import java.util.Calendar;public class CalendargetWeeksInWeekYearExample {public static void main(String args[]){// Creating a calendar objectCalendar cal = Calendar.getInstance();// Displaying the calendarSystem.out.println("Current Calendar: " + cal.getTime());System.out.println("Weeks in week year: " + cal.getWeeksInWeekYear());cal.setWeekDate(1996, 23, 6 );System.out.println("Changed Time: "+cal.getTime());// Get the number of weeks in the week-based yearSystem.out.println("Weeks in week year: " + cal.getWeeksInWeekYear());}}
This code will return an output similar to the following:
Current Time:Sun Sep 10 17:32:33 GMT 2023Weeks in week year :52Changed Time:Fri Jun 07 17:32:33 GMT 1996Weeks in week year :52
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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly16 hours