GregorianCalendar getWeekYear() in Java

getWeekYear(): This method is available in java.util.GregorianCalendar class of Java.

Syntax:

int java.util.GregorianCalendar.getWeekYear()

This method returns the week year represented by this GregorianCalendar.

Parameters: NA

Returns: the week year represented by this GregorianCalendar.

Throws:

IllegalArgumentException - if any of the calendar fields is invalid in non-lenient mode.

Approach

Java

import java.util.GregorianCalendar;

public class GregorianCalendargetWeekYear {
    public static void main(String[] args) {

        GregorianCalendar cal = new GregorianCalendar();

        System.out.println(cal.getWeekYear());
    }
}

Output:

2022


No comments:

Post a Comment