To get the day of the week, use the Calendar.DAY_OF_WEEK.
Firstly, let us get the current date.
java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime());
Now, using GregorianCalendar, set the time.
java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt);
The last step would display the day of the week as shown in the following example.
import java.text.ParseException; public class Demo { public static void main(String[] args) throws ParseException { java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime()); System.out.println("Today's date: "+dt); java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt); // Getting the day of the week System.out.println("Day of the week: "+cal.get(java.util.Calendar.DAY_OF_WEEK)); } }
Today's date: 2018-11-19 Day of the week: 2