java local timeformat without year

2019-03-20 08:17发布

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!

7条回答
何必那么认真
2楼-- · 2019-03-20 09:06

As you probably realize, short formats depends not only on language but also on country. Unfortunately, there are no such patterns built-in in Java. Instead, you might need to use the ones defined by CLDR - search for "pattern" or "Md" (month / day pattern).

However, I must warn you that these patterns might be buggy. Instead you might want to move them to resource file and let the translators deal with them (appropriate comment on what it is and how to deal with it would be required.)

查看更多
登录 后发表回答