Skip to content

Instantly share code, notes, and snippets.

@mlconnor
Created February 21, 2012 19:21
Show Gist options
  • Save mlconnor/1878290 to your computer and use it in GitHub Desktop.
Save mlconnor/1878290 to your computer and use it in GitHub Desktop.
This Java code will print out a list of the locale, country name, iso3166 code, iso639-2 code, and the corresponding date formats used in that country.
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
import java.text.DateFormat;
// this seems to work for everything but hindi and thailand
public class LocaleDates {
static public void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, "UTF8"));
Locale[] list = SimpleDateFormat.getAvailableLocales();
Map<String,List<Locale>> sortedLocales = new TreeMap<String,List<Locale>>();
for ( Locale locale : SimpleDateFormat.getAvailableLocales() ) {
if ( locale.getISO3Country() != null && locale.getISO3Country().length() != 0 ) {
List<Locale> countryLocales = sortedLocales.get(locale.getISO3Country());
if ( countryLocales == null ) {
countryLocales = new ArrayList<Locale>();
sortedLocales.put(locale.getISO3Country(), countryLocales);
}
countryLocales.add(locale);
}
}
out.println("ISO 3166 Country Code ISO639-2 Country Code Country ISO 3166 Country Code ISO639-2 Lang Language Date Format");
for ( String country : sortedLocales.keySet() ) {
List<Locale> countryLocales = sortedLocales.get(country);
for ( Locale locale : countryLocales ) {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
Calendar c = new GregorianCalendar();
c.set(Calendar.MONTH, 5);
c.set(Calendar.DATE, 3);
c.set(Calendar.YEAR, 2012);
String dateResults = df.format(c.getTime());
dateResults = dateResults.replace("2012", "yyyy");
dateResults = dateResults.replace("12", "yyyy");
dateResults = dateResults.replace("06", "MM");
dateResults = dateResults.replace("6", "M");
dateResults = dateResults.replace("03", "dd");
dateResults = dateResults.replace("3", "d");
out.println(locale.getISO3Country() + "\t" +
locale.getCountry() + "\t" +
locale.getDisplayCountry() + "\t" +
locale.getISO3Language() + "\t" +
locale.getLanguage() + "\t" +
locale.getDisplayLanguage() + "\t" +
dateResults);
}
}
out.flush();
//System.out.println("total country count " + sortedLocales.size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment