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 create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023