Java Program to get week number in the year, month


This Java example will show you how to format date in different country format. This uses Locale class & DateFormat class to display date in different Country's format.

import java.util.*;

public class Main {
   public static void main(String[] args) throws Exception {
      Date d1 = new Date();
      Calendar cal = Calendar. getInstance();
      cal.setTime(d1);
      
      System.out.println("today is " + cal.WEEK_OF_YEAR+ " week of the year");
      System.out.println("today is a "+cal.DAY_OF_MONTH + " month of the year");
      System.out.println("today is a "+cal.WEEK_OF_MONTH +" week of the month");
   }
}

 

Output:

today is 3 week of the year
today is a 5 month of the year
today is a 4 week of the month
 
 


Subscribe For Daily Updates

JAVA File IO examples

JAVA Date & Time Progamming Examples

JAVA Collections

Flutter Questions
Android Questions