Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 779
the-alexgator Avatar asked Nov 23 '12 00:11

the-alexgator


People also ask

How do you get present day in Java?

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.

How do I get the day of the week in Java?

To get the day of the week, use Calendar. DAY_OF_WEEK.

Which package will you get the current date in Java?

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.

Can you format calendar in Java?

You can format the calender date object when you want to display and keep that as a string.


1 Answers

Java 8 :

LocalDate.now().getDayOfWeek().name()
like image 199
Mehraj Malik Avatar answered Sep 28 '22 06:09

Mehraj Malik