get Days Of Week - Java java.util

Java examples for java.util:Week

Description

get Days Of Week

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

public class Main {
    public static final String DAY_OF_WEEK_FORMAT = "EEE";

    public static List<String> getDaysOfWeek(Locale locale) {
        List<String> res = new LinkedList<String>();
        Calendar calendar = Calendar.getInstance(locale);
        for (int idx = calendar.getMinimum(Calendar.DAY_OF_WEEK); idx <= calendar
                .getMaximum(Calendar.DAY_OF_WEEK); idx++) {
            //calendar.set(calendar.get(Calendar.YEAR), idx, 1);
            calendar.set(Calendar.DAY_OF_WEEK, idx);
            Date date = new Date(calendar.getTimeInMillis());

            res.add(new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale)
                    .format(date));/*from   w  ww . java 2 s . c o m*/
        }


        if (locale.getLanguage().equalsIgnoreCase("ru")) {
            res.add(res.remove(0));
        }

        return res;
    }
}

Related Tutorials