We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Introduction
- Java Date and Time
- Discussions
Java Date and Time
Java Date and Time
Sort by
recency
|
1513 Discussions
|
Please Login in order to post a comment
public static String findDay(int month, int day, int year) { Calendar cal = Calendar.getInstance(); cal.set(year, month-1, day); String weekDay = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH) .toUpperCase(); return weekDay; }
}
In Java 15 solution
In this code there is one cofusion every begginer will face that is why month -1 is there in this line of code:
calendar.set(year, month-1, day);Explanation : Calendar class represents months as 0-indexed.
So January is 0, February is 1, ... November is 10 and December is 11. So if we are giving Aughust which 8th month. you must pass 7 (i.e., 8 - 1).
as