How to find the day of the week represented by a particular date
In this article, I will be demonstrating how you can find the day of the week represented by a particular date. You can use Java 8 LocalDate class for this. The following code demonstrates this:
LocalDate date = LocalDate.now();DayOfWeek dayOfWeek = LocalDate.of(2019, 8, 11);System.out.println("dayOfWeek="+dayOfWeek);
The LocalDate class has a method called getDayOfWeek. This returns a DayOfWeek enum which corresponds to the day of the week. Here a LocalDate object corresponding to 11th August 2019 is created which corresponds to a Sunday. So when you execute this code, it prints the following output:
dayOfWeek=SUNDAY
Comments
Post a Comment