The example code below helps you to get all weekday names as an array of string. The first method, getWeekdays()
return the full name string while the second method getShortWeekdays()
return the short name of the weekday.
package org.kodejava.text;
import java.text.DateFormatSymbols;
public class WeekdayNames {
public static void main(String[] args) {
DateFormatSymbols dfs = new DateFormatSymbols();
String[] weekdays = dfs.getWeekdays();
for (String weekday : weekdays) {
System.out.println("weekday = " + weekday);
}
String[] shortWeekdays = dfs.getShortWeekdays();
for (String shortWeekday : shortWeekdays) {
System.out.println("shortWeekday = " + shortWeekday);
}
}
}
The results of the code above are:
weekday =
weekday = Sunday
weekday = Monday
weekday = Tuesday
weekday = Wednesday
weekday = Thursday
weekday = Friday
weekday = Saturday
shortWeekday =
shortWeekday = Sun
shortWeekday = Mon
shortWeekday = Tue
shortWeekday = Wed
shortWeekday = Thu
shortWeekday = Fri
shortWeekday = Sat
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024