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) is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. 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