Skip to content

Instantly share code, notes, and snippets.

@coreform
Last active December 28, 2015 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreform/7505003 to your computer and use it in GitHub Desktop.
Save coreform/7505003 to your computer and use it in GitHub Desktop.
Get the day of month suffix in Android, e.g. "1st September, 2013", "1er Septembre 2013", "13th Jan".
public static String getDayOfMonthSuffix(final int n) {
if(n < 1 || n > 31) {
//invalid day of month
return "";
}
String language = Locale.getDefault().getLanguage();
if ("en".equals(language)) {
if (n >= 11 && n <= 13) {
return "th";
}
switch (n % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
} else if("fr".equals(language)) {
if(n == 1) {
return "er";
}
}
return "";
}
@kurthuwig
Copy link

for French you can add "ième" in the plural case.

for "de" = German it is always "ter"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment