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!
now() method of a LocalDate class used to obtain the current date from the system clock in the default time-zone. This method will return LocalDate based on the system clock with the default time-zone to obtain the current date.
To get the day of the week, use Calendar. DAY_OF_WEEK.
There is a class called Clock class which can also represent the current date and time in UTC form. This class comes under the Time package of Java.
You can format the calender date object when you want to display and keep that as a string.
Java 8 :
LocalDate.now().getDayOfWeek().name()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With