Pergunta

How to convert date into marathi using SimpleDateFormat? I tried using following code:

SimpleDateFormat df = new SimpleDateFormat("EEEE, dd MMM yyyy",new Locale("mr", "mr_IN"));
String newDate = df.format(d);

But its not working.

Foi útil?

Solução

Two observations. First I assume your Locale-constructor is not used properly. Instead of:

new Locale("mr", "mr_IN")

you should rather try

new Locale("mr", "IN")

Explanation: The constructor expects as second argument the ISO-3166-country code in two big letters (and as first argument the ISO-639-language code in two small letters), see Javadoc.

Second:

On my system I printed out all available locales using Locale.getAvailableLocales() but was not lucky to see the locale "mr_IN". I hope for you to have a better localized Java configuration. If marathi language is not natively supported then you can finally try following:

DateFormatSymbols dfs =
  DateFormatSymbols.getInstance(new Locale("mr", "IN"));
dfs.setShortMonths(marathiMonthsAsArray);
dfs.setWeekdays(marathiWeekdays);

simpleDateFormat.setDateFormatSymbols(dfs);

Please carefully construct your marathi-language arrays with the proper lengths and indices - study the javadoc closely to avoid some pitfalls. Having done this then you can run your SimpleDateFormat code as marathi-localized.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top