Frage

All I really want to do is format a date using strftime("%x") in the right order. On most platforms a call to setlocale("") is enough. On Android I keep getting !@#$ US dates.

So, does Android not support locales?

War es hilfreich?

Lösung

No. setlocale() and strftime() does not work in Android NDK, except if en_US layout is what you want.

I get the local language from the Java part by:

pLocaleData->pLocaleLanguage = new Locale("en").getDefault().getLanguage();

And the ANSI C localeconv() does not work in Android NDK:

struct lconv *localeconv(void);

Also the standard Unix way of getting user name, does not work in Android.

char *p = getenv("USER");

So you need to use the Java side to get the locale information.

String LocaleCountry = new Locale("en").getDefault().getCountry();
String LocaleLanguage = new Locale("en").getDefault().getLanguage();
String LocaleCurrency = new DecimalFormatSymbols().getCurrency().toString();
String LocaleShortDateTimePattern =new SimpleDateFormat().toPattern();
char LocaleDecimalSeparator = new DecimalFormatSymbols().getDecimalSeparator();
char LocaleThousandSeparator = new DecimalFormatSymbols().getGroupingSeparator();
String LocaleThousandGrouping = 
        String.format("%d;0", new DecimalFormat().getMaximumFractionDigits());
String LocaleNegativePrefix = new DecimalFormat().getNegativePrefix();
String LocaleNegativeSuffix =new DecimalFormat().getNegativeSuffix();
String Operator = Utils.getQwnername(context);

Andere Tipps

According to this the answer is No.

There is no support for locales in the C library / from native code, and this is intentional. As Elliot pointed out, your only hope is to use JNI to get relevant values.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top