Date and Time

How to Get Day from Date in Java using Calendar Object

Table of Contents

Program

import java.sql.Date;
import java.util.Calendar;

public class GetDay 
{
	public static void main(String[] args)
	{
	Date d = new Date(0);
	Calendar cal = Calendar.getInstance();
	cal.setTime(d);
	int day = cal.get(Calendar.DAY_OF_MONTH);
	System.out.println("day of the week : "  + day);
	}
}

Output

day of the week : 4

Description

Value Day
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday

public class Date

The class Date represents a specific instant in time, with millisecond precision.

public static final int DAY_OF_MONTH

Field number for get and set indicating the day of the month. This is a
synonym for DATE. The first day of the month has value 1.

See Also:

DATE, Constant Field Values