Java Calendar get number of week in the year

Description

Java Calendar get number of week in the year

import java.util.Calendar;

public class Main {

  public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();

    if (calendar.isWeekDateSupported()) {
      System.out.println("Number of weeks in this year: " + calendar.getWeeksInWeekYear());
      System.out.println("Current week number: " + calendar.get(Calendar.WEEK_OF_YEAR));
    }//from w  w w  .  j av  a2 s  .  c om

  }
}



PreviousNext

Related