Syntax error Determine day of week in month from Gregorian Calendar in Java

Determine day of week in month from Gregorian Calendar in Java



To work with the GregorianCalendar class, import the following package −

import java.util.GregorianCalendar;

To get the day of week in month, use the following field −

cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)

Above, cal is the GregorianCalendar object we created before −

GregorianCalendar cal = new GregorianCalendar();

The following is an example −

Example

 Live Demo

import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      GregorianCalendar cal = new GregorianCalendar();
      // date information
      System.out.println("Date Information..........");
      System.out.println("Year = " + cal.get(Calendar.YEAR));
      System.out.println("Month = " + (cal.get(Calendar.MONTH) + 1));
      System.out.println("Date = " + cal.get(Calendar.DATE));
      // week
      System.out.println("Day of Week in month = " + cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
   }
}

Output

Date Information..........
Year = 2018
Month = 11
Date = 19
Day of Week in month = 3
Updated on: 2020-06-26T08:35:26+05:30

320 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements