get Days Of Week Array - Java java.util

Java examples for java.util:Week

Description

get Days Of Week Array

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 String[] getDaysOfWeekArray(Locale locale) {
        List<String> days = getDaysOfWeek(locale);

        String[] res = new String[days.size()];

        for (int i = 0; i < days.size(); i++) {
            res[i] = days.get(i);//from  w  w w .  j a va2 s  .  c o m
        }

        return res;
    }

    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));
        }


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

        return res;
    }
}

Related Tutorials