tl;dr
Use java.time classes rather than terrible legacy date-time classes with their crazy month numbering.
LocalDate // Represent a date-only value, without time-of-day, without offset, without time zone.
.of( 2014 , 8 , 8 ) // Or use `Month.AUGUST`.
.getDayOfWeek() // Returns `DayOfWeek` enum object.
.equals( DayOfWeek.FRIDAY ) // Returns true/false.
true
java.time
You are using terrible app old date-time classes that were supplanted years ago by the java.time classes.
Sane numbering
Represent a date-only value with LocalDate
. Note the sane numbering, unlike the legacy classes: 2014
means the year 2014, and months 1-12 mean January-December. So your problem of inadvertently using the wrong month is moot, and never would have occurred if you’d been using the modern and well-designed java.time classes.
LocalDate ld = LocalDate.of( 2014 , 8 , 8 ) ;
For more clarity, use the Month
enum. So month 8 is Month.AUGUST
.
LocalDate ld = LocalDate.of( 2014 , Month.AUGUST , 8 ) ;
Ask for the DayOfWeek
enum object representing the day-of-week on that date.
DayOfWeek dow = ld.getDayOfWeek() ;
Convert
If you have a GregorianCalendar
object in hand given by old code not yet updated to java.time, convert. Convert to a ZonedDateTime
. Then extract the DayOfWeek
.
ZonedDateTime zdt = myGregCal.toZonedDateTime() ;
DayOfWeek dow = zdt.getDayOfWeek() ;