Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

In this page you can find the example usage for java.util Locale Locale.

Prototype

public Locale(String language, String country) 

Source Link

Document

Construct a locale from language and country.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static String[] get_Currency_Name_And_Currency_Code(String iso2) {
    String[] str = new String[2];
    Locale locale = new Locale("", iso2);
    Currency currency = Currency.getInstance(locale);
    str[0] = currency.getDisplayName(Locale.ENGLISH);
    str[1] = currency.toString();/*from   www .  j a  v  a2s  . c  om*/
    return str;

}

From source file:Main.java

private static Map<String, String> initCountries() {
    Map<String, String> countries = new HashMap<String, String>();
    for (String iso : Locale.getISOCountries()) {
        Locale l = new Locale(loc, iso);
        countries.put(l.getDisplayCountry(), iso);
    }//from  ww  w . j  ava  2s.  c  o m
    return countries;
}

From source file:Main.java

private static DateFormat getHourMinuteDateFormat() {
    if (hourMinuteDateFormat == null) {
        hourMinuteDateFormat = new SimpleDateFormat("HH:mm", new Locale("pt", "BR"));
    }/*from   w w w  . j av a  2  s.  com*/
    return hourMinuteDateFormat;
}

From source file:Main.java

public static String getCountryCode(String spinnerText) {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {/*from   w  w  w .  j  a  va2s. c  o  m*/
            Currency currency = Currency.getInstance(locale);
            String proposedSpinnerText = locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";

            if (proposedSpinnerText.equals(spinnerText)) {
                return countryCode;
            }
        } catch (Exception e) {

        }
    }
    return "";
}

From source file:Main.java

public static String findDateWithFormat(String findDate, String format) {
    findDate = findDate.replace(" ", "").replace("-", "").replace(":", "").replace("/", "").replace(".", "");

    Locale currentLocale = new Locale("KOREAN", "KOREA");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", currentLocale);
    SimpleDateFormat returnFormatter = new SimpleDateFormat(format, currentLocale);
    String returnValue = "";
    try {/*from  ww  w  . ja  v  a  2 s  . c  o  m*/
        Date fDate = formatter.parse(findDate);
        returnValue = returnFormatter.format(fDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return returnValue;
}

From source file:Main.java

public static String getDayAndMonthFromDateString(String date) {
    java.util.Calendar calendar = getCalendarFromStringDate(date);
    System.out.println("Date ->" + date);
    DateFormatSymbols symbols = new DateFormatSymbols(new Locale("es", "ES"));
    String[] monthNames = symbols.getMonths();

    return calendar.get(java.util.Calendar.DAY_OF_MONTH) + " DE "
            + monthNames[calendar.get(java.util.Calendar.MONTH)];
}

From source file:Main.java

public static ArrayList<String> getCountriesArray() {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<String>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {// w  ww .j  av  a  2 s .  co m
            Currency currency = Currency.getInstance(locale);
            countries.add(locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")");
        } catch (Exception e) {

        }
    }
    Collections.sort(countries);
    return countries;
}

From source file:Main.java

public static String dateFormatter(String date) {
    // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat sdf2 = new SimpleDateFormat("dd.MM.yyyy", new Locale("tr", "TR"));
    Date d;//from  ww w  .  ja  v a  2 s. c  om
    String formatdate = null;
    try {
        d = sdf.parse(date);
        formatdate = sdf2.format(d);
    } catch (ParseException ex) {
        return date;
    }
    return formatdate;
}

From source file:Main.java

public static void setLanguage(Context context, String language) {
    Locale locale;//from   w w w.  j  a v a 2s.  c o m
    if (TextUtils.isEmpty(language)) {
        locale = Locale.getDefault();
    } else if (language.length() == 5 && language.charAt(2) == '_') {
        // language is in the form: en_US
        locale = new Locale(language.substring(0, 2), language.substring(3));
    } else {
        locale = new Locale(language);
    }

    Configuration config = new Configuration();
    config.locale = locale;
    Resources resources = context.getResources();
    resources.updateConfiguration(config, resources.getDisplayMetrics());
}

From source file:Main.java

private static DateFormat getDayMonthDateFormat() {
    if (dayMonthDateFormat == null) {
        dayMonthDateFormat = new SimpleDateFormat("dd/MM", new Locale("pt", "BR"));
    }//from  w w w .ja v a2s. c o  m
    return dayMonthDateFormat;
}