get Short Weekdays - Android java.util

Android examples for java.util:Week

Description

get Short Weekdays

Demo Code


import android.util.Log;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Locale;

public class Main{
    private static final String LOG_TAG = CalendarUtil.class
            .getSimpleName();/*from www. j  ava 2s .  c o  m*/
    public static ArrayList<String> getShortWeekdays() {
        Log.d(LOG_TAG, "getShortWeekdays() is called.");
        return getShortWeekdays(Locale.getDefault());
    }
    public static ArrayList<String> getShortWeekdays(final Locale locale) {
        Log.d(LOG_TAG, "getShortWeekdays(final Locale locale) is called.");
        final String[] shortWeekdays = DateFormatSymbols
                .getInstance(locale).getShortWeekdays();
        final ArrayList<String> shortWeekdaysList = new ArrayList<String>(7);
        // Add days starting from Monday to Saturday
        Collections.addAll(shortWeekdaysList, Arrays.copyOfRange(
                shortWeekdays, Calendar.MONDAY, Calendar.SATURDAY + 1));
        // And finally add sunday
        shortWeekdaysList.add(shortWeekdays[Calendar.SUNDAY]);
        return shortWeekdaysList;
    }
}

Related Tutorials