Java GregorianCalendar.getWeeksInWeekYear() example

 Posted On  | Pooja Lakkihal 

In this java tutorial, You will learn how to get the number of weeks in the week year represented by this GregorianCalendar. Java GregorianCalendar.getWeeksInWeekYear() method returns number of weeks in the week year.

Returns the number of weeks in the week year represented by this GregorianCalendar.

syntax

public int getWeeksInWeekYear()

Returns

The number of weeks in the week year.

Java GregorianCalendar getWeeksInWeekYear() example

  • Create GregorianCalendar instance by invoking static method (GregorianCalendar) GregorianCalendar.getInstance();. You have to type it into GregorianCalendar, otherwise you will get Type mismatch: cannot convert from Calendar to GregorianCalendar error.
  • gregorianCalendar.getTime(); This will get the calendar current time Zone.
  • gregorianCalendar.getWeeksInWeekYear(); It returns the number of weeks in the year.
package com.technicalkeeda;

import java.util.GregorianCalendar;

public class App {

    public static void main(String[] args) {

        GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();

        System.out.println("Current time :- " + gregorianCalendar.getTime());
        System.out.println("Weeks in Year 2018 :- " + gregorianCalendar.getWeeksInWeekYear());
    }
}

output

Current time :- Fri Feb 02 16:01:19 IST 2018
Weeks in Year 2018 :- 52


© technicalkeeda.com 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0291 seconds.