Question

Hi there everybody: is there any way I can parse a month -my app will be both in dutch and in english, so for example October could be either Oktober or October- and depending on it, set the corresponding month of the year? (October would be the 10th for example).

The server always replies with a String (which is the name of a month IN DUTCH) but I need to parse this, because the app will be also in ENGLISH).

Thanks a lot in advance!

Was it helpful?

Solution

Use DateFormat symbols which is locale aware. Don't try to hard code month names.

DateFormatSymbols(Locale.DUTCH).getMonths()[Calendar.OCTOBER]; // returns Oktober

Or

Calendar.getDisplayNames(MONTH, ALL_STYLES, Locale.DUTCH); // returns a map which you can use to match strings

If you are getting the month name string from somewhere else, you can convert it to a month number:

DateTime instance = format.withLocale(Locale.DUTCH).parseDateTime("Oktober");  
int monthNum = instance.getMonthOfYear();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top