How to get day name from date in java

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

There are multiple ways to get day name 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 name from date in java.

Related Posts

  • Convert Date to LocalDate in java
    12 January

    Java Date to LocalDate

    Table of ContentsUsing toInstant() method of Date classUsing toInstant() method of Date classUsing java.sql.Date In this post, we will see how to convert Date to LocalDate in java. Sometimes, we may need to convert Date to new Java 8 APIs and vice versa. There are multiple ways to convert Date to LocalDate in java. Read […]

  • Convert LocalDate to Date in java
    11 January

    Java LocalDate to Date

    Table of ContentsUsing Instant objectUsing java.sql.Date In this post, we will see how to convert LocalDate to Date. Java 8 has introduced a lot of new APIs for Date and time. There can be many ways to convert Java LocalDateTime to date. Using Instant object You can convert LocalDate to Date using Instant object which […]

  • 22 December

    How to add days to date in java

    Learn about how to add days to Date using Calendar and LocalDate in java.

  • 23 March

    Get current timestamp in java

    Table of ContentsUsing Java 8’s Instant classUsing Instant.now()Using date.toInstant()Using timestamp.toInstant()Using java.sql.TimestampConclusion In this post, we will see how to get current timestamp in java. There are multiple ways to get current timestamp in java. Using Java 8’s Instant class There are three ways to get timestamp using Java 8‘s java.time.Instant class. Using Instant.now() [crayon-617138dd46edc409000974/] Using […]

  • 22 April

    How to calculate difference between two dates in java

    In this post, we will see how to calculate difference between two dates. Sometimes we have requirement to find no. of days between two dates or no. of hours between two dates. Java Program: [crayon-617138dd479a8143405293/] When you run above program, you will get following output: [crayon-617138dd479ae492068164/]

  • 25 January

    How to convert String to Date in java

    In this post, we will see how to convert String to Date object in java. It is used when we have formatted String and need to convert it to Date object.You may also check how to convert Date to String Java program: [crayon-617138dd4818f464527321/] When you run above program, you will get following output: [crayon-617138dd48196661845890/]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.