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:
Some examples of options for TextStyle and Locale to choose from.
TextStyle Option | Output Example (English Locale) |
|---|---|
FULL | Monday |
FULL_STANDALONE | Monday |
SHORT | Mon |
SHORT_STANDALONE | Mon |
NARROW | M |
NARROW_STANDALONE | M |
| Locale Option | Output Example (Day Name in English) |
|---|---|
Locale.ENGLISH | Monday |
Locale.FRENCH | lundi |
Locale.GERMAN | Montag |
Locale.ITALIAN | lunedì |
Locale.JAPANESE | 月曜日 |
Locale.CHINESE | 星期一 |
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!