Android Date Format String Create getDateFormatSymbols(Locale locale)

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

Description

Gets the DateFormatSymbols based on the given locale.

License

Apache License

Parameter

Parameter Description
locale the Locale used to get the correct DateFormatSymbols

Return

the symbols

Declaration

public static final DateFormatSymbols getDateFormatSymbols(Locale locale) 

Method Source Code

//package com.java2s;
/*//from  www .j  av  a  2 s  .c o m
 *  Copyright 2001-2012 Stephen Colebourne
 *
 *  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 java.lang.reflect.Method;
import java.text.DateFormatSymbols;

import java.util.Locale;

public class Main {
    /**
     * Gets the {@link DateFormatSymbols} based on the given locale.
     * <p>
     * If JDK 6 or newer is being used, DateFormatSymbols.getInstance(locale) will
     * be used in order to allow the use of locales defined as extensions.
     * Otherwise, new DateFormatSymbols(locale) will be used.
     * See JDK 6 {@link DateFormatSymbols} for further information.
     * 
     * @param locale  the {@link Locale} used to get the correct {@link DateFormatSymbols}
     * @return the symbols
     * @since 2.0
     */
    public static final DateFormatSymbols getDateFormatSymbols(Locale locale) {
        try {
            Method method = DateFormatSymbols.class.getMethod(
                    "getInstance", new Class[] { Locale.class });
            return (DateFormatSymbols) method.invoke(null,
                    new Object[] { locale });
        } catch (Exception ex) {
            return new DateFormatSymbols(locale);
        }
    }
}

Related

  1. getFormat(String pattern)
  2. changeFormat(String gmtString, String orgFormat, String format)
  3. convertFormat(String src, String f1, String f2)
  4. dateFormatToString(int date, Context context)
  5. getGMTDateFormat()