How to find the day of the week represented by a particular date
Posted On
Posted By admin
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
If you like this post, please do let me know via the comments box below. You can also connect with me via my Facebook Page or subscribe to my Youtube channel!