How to Get Day from Date in Java

In this post, we will see how to get day from date in java.

There are multiple ways to get day from date in java. Let’s go through them.

Using java.util.Date

You can use Calendar class to get day of week in number and SimpleDateFormat if you need it in text format like Tuesday.

Let’s see with the help of example:

Output:

Day of week in number:3
Day of week in text:Tuesday

Here day of week in number ranges from 1(Calendar.SUNDAY) to 7(Calendar.SATURAY). Since date of week is tuesday, that’s why we got output as 3

Using java.time.LocalDate

You can use getDayOfWeek() method of LocalDate class to get day name of week from date in java. It will work for Java 8 or later.

Let’s see with the help of example:

Output:

Day of week in number:2
Day of week in text:TUESDAY

Here day of week in number ranges from 1(Monday) to 7(Sunday) as it has its own enum. Since date of week is TUESDAY, that’s why we got output as 2
That’s all about How to day from date in java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *