如何自定义Java日期格式

n17*_*911 0 java

从java doc中,MEDIUM格式为:MEDIUM更长,例如1952年1月12日

http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html

如何自定义它以便我不显示年份?拼出"Jan"到1月份?

我自己需要这样做吗?*在','*之后将字符串切断,将月份短名称(Jan)映射到其长名称(1月)?

谢谢.

Rob*_*ska 11

使用SimpleDateFormat:

// For months like "Jan"
String formatted = new SimpleDateFormat("MMM dd").format(new Date());

// For months like "January"
String formatted = new SimpleDateFormat("MMMMM dd").format(new Date());
Run Code Online (Sandbox Code Playgroud)