Syntax error Java Program to get the day of the week from GregorianCalendar

Java Program to get the day of the week from GregorianCalendar



For GregorianCalendar class, import the following package.

import java.util.GregorianCalendar;

Create an object.

GregorianCalendar calendar = new GregorianCalendar();

To get the day of the week, use the following field.

GregorianCalendar.DAY_OF_WEEK

The following is an example.

Example

 Live Demo

import java.util.Calendar;
import java.util.GregorianCalendar;
public class Demo {
   public static void main(String[] a) {
      GregorianCalendar calendar = new GregorianCalendar();
      System.out.println("Day of Week = " + calendar.get(GregorianCalendar.DAY_OF_WEEK));
      System.out.println("Date = " + calendar.get(GregorianCalendar.DATE));
      System.out.println("Month = " + calendar.get(GregorianCalendar.MONTH));
      System.out.println("Year = " + calendar.get(GregorianCalendar.YEAR));
   }
}

Output

Day of Week = 2
Date = 19
Month = 10
Year = 2018
Updated on: 2020-06-27T09:36:40+05:30

434 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements