How do I get a list of weekday names?

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
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.