Java Program to get the day of the week from GregorianCalendar

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 17-Dec-2018 16:43:25
Advertisements