Find Day of the week from any Calendar date using Java code



If we have a date, and need to find which day of the week it was instantly, that would a really useful function, isn't it? This is also a useful function which can be used on a webpage having Calendar logic, or a Delivery website which wants to show which is the day of the week on which your order will be delivered. 

Java has a very useful inbuilt function which we can use to get this functionality, and we'll show you how!

For utilizing the functionality, you have to import a Java library: 

import java.time.LocalDate;

Once you have the library, the code is really easy. Let's write a small working function.

 * Function to return Day of the week
 * @author
 * @param month
 * @param day
 * @param year
 * @return
public static String findDay(int month, int day, int year) {
	LocalDate ldt = LocalDate.of(year, month, day);
	return String.valueOf(ldt.getDayOfWeek());


That's it! Isn't that a really simple logic. That's the magic of Java libraries doing all the heavy lifting. 

Thanks for Reading the Article. If you have reached this far, we hope that the article was useful to you! Please Like/Share/Follow us on FacebookTwitterTumblr. 


Popular posts from this blog

Calculate Your CTC Salary Hike Percentage - Online Calculator to find your New Salary

Find the Longest Streak of 1's in a Binary Array using Java Code

Java Program to Read a Properties file and return a Property Value

Create a File logging Utility using Java Code

What is my IP Address - How to find your IP address on Local Network using Command Prompt, and External Network using JavaScript Code