I get an integer and I need to convert to a month names in various locales:
Example for locale en-us:
1 -> January
2 -> February
Example for locale es-mx:
1 -> Enero
2 -> Febrero
I get an integer and I need to convert to a month names in various locales:
Example for locale en-us:
1 -> January
2 -> February
Example for locale es-mx:
1 -> Enero
2 -> Febrero
java.time
Since Java 1.8 (or 1.7 & 1.6 with the ThreeTen-Backport) you can use this:
Note that
integerMonth
is 1-based, i.e. 1 is for January. Range is always from 1 to 12 for January-December (i.e. Gregorian calendar only).Apparently in Android 2.2 there is a bug with SimpleDateFormat.
In order to use month names you have to define them yourself in your resources:
And then use them in your code like this:
Here's how I would do it. I'll leave range checking on the
int month
up to you.There is an issue when you use DateFormatSymbols class for its getMonthName method to get Month by Name it show Month by Number in some Android devices. I have resolved this issue by doing this way:
In String_array.xml
In Java class just call this array like this way:
Happy Coding :)
I would use SimpleDateFormat. Someone correct me if there is an easier way to make a monthed calendar though, I do this in code now and I'm not so sure.