How to Get the Day Name From Date In Java


We can make use of the java.time.format.TextStyle class to get the day name from date in Java 8 and above.


Example:

package org.code2care.examples;

import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Locale;

public class DayFromDateJava {

    public static void main(String[] args) {

        LocalDate date = LocalDate.now();
        String dayName = date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH);
        System.out.println("The day of the date is : " + dayName);
    }
}
Output:

The day of the date is : Wednesday


Some examples of options for TextStyle and Locale to choose from.

TextStyle OptionOutput Example (English Locale)
FULLMonday
FULL_STANDALONEMonday
SHORTMon
SHORT_STANDALONEMon
NARROWM
NARROW_STANDALONEM


Locale OptionOutput Example (Day Name in English)
Locale.ENGLISHMonday
Locale.FRENCHlundi
Locale.GERMANMontag
Locale.ITALIANlunedì
Locale.JAPANESEζœˆζ›œζ—₯
Locale.CHINESEζ˜ŸζœŸδΈ€

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright Β© Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap