I like to format the local timeformat into a string without the year. At the moment I am able to show the local format containing the year:
java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT);
String dateString = df.format(date);
therefore i receive an time string output like
12.03.2012
03/12/2012
for the different countries. Now i like to get a short form like
12.03.
03/12
how would i do this?
thanks for your help!
You can use
SimpleDateFormat:Output:
EDIT:
After researching locale formats further, and expanding on Peters answer, here’s some code to demonstrator differences between
toPattern()andtoLocalizedPattern():Produces following output:
So in conclusion, to display a localized date without a year:
String yearlessPattern = DateFormat.getDateInstance(DateFormat.SHORT).toPattern().replaceAll("\\W?[Yy]+\\W?", "");