the-alexgator the-alexgator - 3 months ago 15
Java Question

Get Current Day (Monday, Tuesday, etc) in Java

I am working on a program that asks the user which day they would like to see a lunch menu for. They can enter any day by name (Monday, Tuesday, etc.). This works well, but I would also like them to be able to enter "Today" and then have the program get the current date and then check the menu for that value.

How would I do this?

Thanks!

Answer

You can use java.util.Calendar:

Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);