Skip to Content

Get Week of month and year using Java Calendar

  1. /*
  2.   Get Week of month and year using Java Calendar
  3.   This example shows how to get current week of month and curent week of year  
  4.   using Java Calendar class.
  5. */
  6.  
  7. import java.util.Calendar;
  8.  
  9. public class GetWeekOfMonthAndYear {
  10.  
  11.   public static void main(String[] args) {
  12.  
  13.     //create Calendar instance
  14.     Calendar now = Calendar.getInstance();
  15.    
  16.     System.out.println("Current week of month is : " +
  17.                 now.get(Calendar.WEEK_OF_MONTH));
  18.                
  19.     System.out.println("Current week of year is : " +
  20.                 now.get(Calendar.WEEK_OF_YEAR));
  21.  
  22.     now.add(Calendar.WEEK_OF_MONTH, 1);
  23.     System.out.println("date after one year : " + (now.get(Calendar.MONTH) + 1)
  24.                         + "-"
  25.                         + now.get(Calendar.DATE)
  26.                         + "-"
  27.                         + now.get(Calendar.YEAR));
  28.  
  29.    
  30.   }
  31. }
  32.  
  33. /*
  34. Typical output would be
  35. Current week of month is : 5
  36. Current week of year is : 52
  37. */