Java Week Day getWeekdayNames(Locale locale)

Here you can find the source of getWeekdayNames(Locale locale)

Description

Get an array of weekday names for a given locale.

License

Open Source License

Parameter

Parameter Description
locale Locale

Return

String[]

Declaration

public static String[] getWeekdayNames(Locale locale) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2005 Will Roethel.//from w w  w.ja v  a2s.co  m
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    Will Roethel - initial API and implementation
*******************************************************************************/

import java.util.GregorianCalendar;
import java.util.Locale;
import java.text.SimpleDateFormat;

public class Main {
    /**
     * Get an array of weekday names for a given locale.
     * @param locale Locale
     * @return String[]
     */
    public static String[] getWeekdayNames(Locale locale) {
        // get a norm calendar using the default locale
        SimpleDateFormat dayFormatter = new SimpleDateFormat("E", locale);
        String[] weekdayName = new String[7];
        GregorianCalendar cal = new GregorianCalendar(2005, java.util.Calendar.JANUARY, 1);
        int currentWeekday = cal.get(java.util.Calendar.DAY_OF_WEEK);
        int daysUntilNextSunday = java.util.Calendar.SATURDAY - currentWeekday + 1;
        cal.add(java.util.Calendar.DAY_OF_MONTH, daysUntilNextSunday);
        for (int iDay = 0; iDay < 7; iDay++) {
            weekdayName[iDay] = dayFormatter.format(cal.getTime()).subSequence(0, 1).toString();
            cal.add(java.util.Calendar.DAY_OF_MONTH, 1);
        }
        return weekdayName;
    }

    /**
     * Get an array of weekday names for the default locale.
     * @return String[]
     */
    public static String[] getWeekdayNames() {
        return getWeekdayNames(Locale.getDefault());
    }
}

Related

  1. getWeekDayByDate(Date date)
  2. getWeekDayCN()
  3. getWeekdayForInt(int value)
  4. getWeekdayName(Date date)
  5. getWeekdayNames()
  6. getWeekDayNUM()
  7. getWeekdayOfDateTime(String datetime)
  8. getWeekdays(DateFormatSymbols symbols)
  9. getWeekDayStr(int dayInWeek)