number to Week day name - Android java.util

Android examples for java.util:Week

Description

number to Week day name

Demo Code


import android.util.Log;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import sun.bob.mcalendarview.CellConfig;
import sun.bob.mcalendarview.vo.DateData;

public class Main{
    /** /*from  w  ww  . j  av  a2s.  c  o  m*/
     * The number to Week
     * @param number - Number day of Week (on the code Sunday is equal 7)
     * @return [String] - abbreviated name of the days of the week
     */
    public static String number2Week(int number) {
        if (number < 1 || number > 7)
            return null; //Day of Week 1-7
        if (number == 7) {
            number = 1;
        } else {
            number = number + 1;
        }
        final DateFormatSymbols symbols = new DateFormatSymbols(); //use user locale
        final String nameDayOfWeek = symbols.getShortWeekdays()[number]; //Short name or getWeekdays for complete name
        return nameDayOfWeek.toUpperCase(); //name to uppercase
    }
}

Related Tutorials