Here you can find the source of getMonthString(int month, int abbrev)
Parameter | Description |
---|---|
month | One of Calendar#JANUARY Calendar.JANUARY , Calendar#FEBRUARY Calendar.FEBRUARY , etc. |
abbrev | One of #LENGTH_LONG , #LENGTH_MEDIUM , or #LENGTH_SHORTEST . Undefined lengths will return #LENGTH_MEDIUM but may return something different in the future. |
public static String getMonthString(int month, int abbrev)
/*/* w w w . j a v a 2 s.co 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[] sMonthsLong = new int[] { com.android.internal.R.string.month_long_january, com.android.internal.R.string.month_long_february, com.android.internal.R.string.month_long_march, com.android.internal.R.string.month_long_april, com.android.internal.R.string.month_long_may, com.android.internal.R.string.month_long_june, com.android.internal.R.string.month_long_july, com.android.internal.R.string.month_long_august, com.android.internal.R.string.month_long_september, com.android.internal.R.string.month_long_october, com.android.internal.R.string.month_long_november, com.android.internal.R.string.month_long_december, }; private static final int[] sMonthsMedium = new int[] { com.android.internal.R.string.month_medium_january, com.android.internal.R.string.month_medium_february, com.android.internal.R.string.month_medium_march, com.android.internal.R.string.month_medium_april, com.android.internal.R.string.month_medium_may, com.android.internal.R.string.month_medium_june, com.android.internal.R.string.month_medium_july, com.android.internal.R.string.month_medium_august, com.android.internal.R.string.month_medium_september, com.android.internal.R.string.month_medium_october, com.android.internal.R.string.month_medium_november, com.android.internal.R.string.month_medium_december, }; private static final int[] sMonthsShortest = new int[] { com.android.internal.R.string.month_shortest_january, com.android.internal.R.string.month_shortest_february, com.android.internal.R.string.month_shortest_march, com.android.internal.R.string.month_shortest_april, com.android.internal.R.string.month_shortest_may, com.android.internal.R.string.month_shortest_june, com.android.internal.R.string.month_shortest_july, com.android.internal.R.string.month_shortest_august, com.android.internal.R.string.month_shortest_september, com.android.internal.R.string.month_shortest_october, com.android.internal.R.string.month_shortest_november, com.android.internal.R.string.month_shortest_december, }; /** * 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 localized string for the month of the year. * @param month One of {@link Calendar#JANUARY Calendar.JANUARY}, * {@link Calendar#FEBRUARY Calendar.FEBRUARY}, etc. * @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_MEDIUM}, * or {@link #LENGTH_SHORTEST}. * Undefined lengths will return {@link #LENGTH_MEDIUM} * but may return something different in the future. * @return Localized month of the year. */ public static String getMonthString(int month, int abbrev) { // Note that here we use sMonthsMedium for MEDIUM, SHORT and SHORTER. // This is a shortcut to not spam the translators with too many variations // of the same string. If we find that in a language the distinction // is necessary, we can can add more without changing this API. int[] list; switch (abbrev) { case LENGTH_LONG: list = sMonthsLong; break; case LENGTH_MEDIUM: list = sMonthsMedium; break; case LENGTH_SHORT: list = sMonthsMedium; break; case LENGTH_SHORTER: list = sMonthsMedium; break; case LENGTH_SHORTEST: list = sMonthsShortest; break; default: list = sMonthsMedium; break; } Resources r = Resources.getSystem(); return r.getString(list[month - Calendar.JANUARY]); } }