Last active
December 28, 2015 13:08
-
-
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".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for French you can add "ième" in the plural case.
for "de" = German it is always "ter"