Given the day, month, and year, the task is to find the corresponding day of the week using SimpleDateFormat class in Java.
Explanation: The day corresponding to the date 11-08-2020 is tuesday.
Explanation: The day corresponding to the date 17-08-2006 is thursday.
- Input the date, month, and year from the user as integer type.
- Check if the date, month, and year are in the required range. If not, raise an error message.
- Convert the input into Date type using SimpleDateFormat class.
- Format the date to the corresponding day of the week using SimpleDateFormat class.
- Print the corresponding day of the week.
Note: If you want the full name of the day (ex: Sunday, Monday), use “EEEE”. If you want the shorter version of the name of the day (ex: Sun, Mon), use “EE”.
Below is the implementation of the above approach:
Day of week on 17-8-2006 : Thursday
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.