Description
Return a string for the day of the week.
License
Apache License
Parameter
Parameter | Description |
---|
dayOfWeek | One of Calendar#SUNDAY Calendar.SUNDAY , Calendar#MONDAY Calendar.MONDAY , etc. |
abbrev | One of #LENGTH_LONG , #LENGTH_SHORT , #LENGTH_MEDIUM , or #LENGTH_SHORTEST . Note that in most languages, #LENGTH_SHORT will return the same as #LENGTH_MEDIUM . Undefined lengths will return #LENGTH_MEDIUM but may return something different in the future. |
Exception
Parameter | Description |
---|
IndexOutOfBoundsException | if the dayOfWeek is out of bounds. |
Declaration
public static String getDayOfWeekString(int dayOfWeek, int abbrev)
Method Source Code
/*/*from w ww . ja va 2 s . c o m*/
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.android.internal.R;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
public class Main{
private static final int[] sDaysLong = new int[] {
com.android.internal.R.string.day_of_week_long_sunday,
com.android.internal.R.string.day_of_week_long_monday,
com.android.internal.R.string.day_of_week_long_tuesday,
com.android.internal.R.string.day_of_week_long_wednesday,
com.android.internal.R.string.day_of_week_long_thursday,
com.android.internal.R.string.day_of_week_long_friday,
com.android.internal.R.string.day_of_week_long_saturday, };
private static final int[] sDaysMedium = new int[] {
com.android.internal.R.string.day_of_week_medium_sunday,
com.android.internal.R.string.day_of_week_medium_monday,
com.android.internal.R.string.day_of_week_medium_tuesday,
com.android.internal.R.string.day_of_week_medium_wednesday,
com.android.internal.R.string.day_of_week_medium_thursday,
com.android.internal.R.string.day_of_week_medium_friday,
com.android.internal.R.string.day_of_week_medium_saturday, };
private static final int[] sDaysShort = new int[] {
com.android.internal.R.string.day_of_week_short_sunday,
com.android.internal.R.string.day_of_week_short_monday,
com.android.internal.R.string.day_of_week_short_tuesday,
com.android.internal.R.string.day_of_week_short_wednesday,
com.android.internal.R.string.day_of_week_short_thursday,
com.android.internal.R.string.day_of_week_short_friday,
com.android.internal.R.string.day_of_week_short_saturday, };
private static final int[] sDaysShortest = new int[] {
com.android.internal.R.string.day_of_week_shortest_sunday,
com.android.internal.R.string.day_of_week_shortest_monday,
com.android.internal.R.string.day_of_week_shortest_tuesday,
com.android.internal.R.string.day_of_week_shortest_wednesday,
com.android.internal.R.string.day_of_week_shortest_thursday,
com.android.internal.R.string.day_of_week_shortest_friday,
com.android.internal.R.string.day_of_week_shortest_saturday, };
/**
* Request the full spelled-out name. For use with the 'abbrev' parameter of
* {@link #getDayOfWeekString} and {@link #getMonthString}.
*
* @more <p>
* e.g. "Sunday" or "January"
*/
public static final int LENGTH_LONG = 10;
/**
* Request an abbreviated version of the name. For use with the 'abbrev'
* parameter of {@link #getDayOfWeekString} and {@link #getMonthString}.
*
* @more <p>
* e.g. "Sun" or "Jan"
*/
public static final int LENGTH_MEDIUM = 20;
/**
* Request a shorter abbreviated version of the name.
* For use with the 'abbrev' parameter of {@link #getDayOfWeekString} and {@link #getMonthString}.
* @more
* <p>e.g. "Su" or "Jan"
* <p>In most languages, the results returned for LENGTH_SHORT will be the same as
* the results returned for {@link #LENGTH_MEDIUM}.
*/
public static final int LENGTH_SHORT = 30;
/**
* Request an even shorter abbreviated version of the name.
* Do not use this. Currently this will always return the same result
* as {@link #LENGTH_SHORT}.
*/
public static final int LENGTH_SHORTER = 40;
/**
* Request an even shorter abbreviated version of the name.
* For use with the 'abbrev' parameter of {@link #getDayOfWeekString} and {@link #getMonthString}.
* @more
* <p>e.g. "S", "T", "T" or "J"
* <p>In some languages, the results returned for LENGTH_SHORTEST will be the same as
* the results returned for {@link #LENGTH_SHORT}.
*/
public static final int LENGTH_SHORTEST = 50;
/**
* Return a string for the day of the week.
* @param dayOfWeek One of {@link Calendar#SUNDAY Calendar.SUNDAY},
* {@link Calendar#MONDAY Calendar.MONDAY}, etc.
* @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_SHORT},
* {@link #LENGTH_MEDIUM}, or {@link #LENGTH_SHORTEST}.
* Note that in most languages, {@link #LENGTH_SHORT}
* will return the same as {@link #LENGTH_MEDIUM}.
* Undefined lengths will return {@link #LENGTH_MEDIUM}
* but may return something different in the future.
* @throws IndexOutOfBoundsException if the dayOfWeek is out of bounds.
*/
public static String getDayOfWeekString(int dayOfWeek, int abbrev) {
int[] list;
switch (abbrev) {
case LENGTH_LONG:
list = sDaysLong;
break;
case LENGTH_MEDIUM:
list = sDaysMedium;
break;
case LENGTH_SHORT:
list = sDaysShort;
break;
case LENGTH_SHORTER:
list = sDaysShort;
break;
case LENGTH_SHORTEST:
list = sDaysShortest;
break;
default:
list = sDaysMedium;
break;
}
Resources r = Resources.getSystem();
return r.getString(list[dayOfWeek - Calendar.SUNDAY]);
}
}
Related
- getDayofWeekInMonth(String year, String month, String weekOfMonth, String dayOfWeek)
- getDayOfWeek(String year, String month, String day)
- getDayOfWeek(String date)
- getDayOfWeek(Date date)