Get a List of Months by Locale in Android…

October 5, 2011

I was working with a client trying to decide on long and short DateFormats for an international mobile application.  (Yes, that’s a mouthful.)

I wasn’t able to quickly find any documentation on the Java SimpleDateFormat strings by locale…so I did what any Passionate Programmer would do, and I wrote a method to do it for me.

[OutputStreamWriter](https://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+outputstreamwriter) out =new[OutputStreamWriter](https://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+outputstreamwriter)(openFileOutput(         “months-by-locale.txt”, 0));

for(Locale l :Locale.getAvailableLocales())
{
out.write(“Locale = “+ l.getDisplayLanguage()+“, “+ l.getDisplayCountry());
out.write(“n”);

out.write(”    Long Months…”);
out.write(“n”);
String[] months =newDateFormatSymbols(l).getMonths();
for(String m : months)
{
out.write(”        “+ m);
out.write(“n”);
}
out.write(“n”);

out.write(”    Short Months…”);
out.write(“n”);
String[] smonths =newDateFormatSymbols(l).getShortMonths();
for(String m : smonths)
{
out.write(”        “+ m);
out.write(“n”);
}
out.write(“n”);
}
out.close();

Then, I needed to get this file off of my emulator. To do that, I opened the DDMS perspective, selected my emulator in the Devices tab (emulator-5554), and navigated to datadata(applicaton name)files(file name).

Build awesome things for fun.

Check out our current openings for your chance to make awesome things with creative, curious people.

Explore SEP Careers »

You Might Also Like