tl;dr
So, if I pass it (17/11/2020) it should return "TUESDAY".
Use java.time.
java.time.LocalDate
.of( 2020 , 11 , 17 )
.getDayOfWeek()
.toString()
TUESDAY
Details
Never use Calendar
, GregorianCalendar
, and so on. Their crazy month numbering where November = 10 is but one of many reasons to avoid these legacy classes.
Use modern java.time classes instead of terrible legacy date-time classes.
String input = "17/11/2020" ;
DateTimeFormatter f = DateTimeFormatter.ofPattern( "dd/MM/uuuu" ) ;
LocalDate localDate = LocalDate.parse( input , f ) ;
DayOfWeek dow = localDate.getDayOfWeek() ;
System.out.println( dow.toString() ) ;
See this code run live at IdeOne.com.
TUESDAY
In real work, use DayOfWeek::getDisplayName
to get text of the localized name of the day of week.
java.time.LocalDate
.of( 2020 , 11 , 17 )
.getDayOfWeek()
.getDisplayName(
TextStyle.FULL_STANDALONE ,
Locale.CANADA_FRENCH
)
See this code run live at IdeOne.com.
mardi
All this has been covered many many times on Stack Overflow. Search to learn more.