Android中的SimpleDateFormat将当前日期定为02/32/2011

Rus*_*art 2 java android date simpledateformat

今天是2011年2月1日.我正在尝试使用SimpleDateFormat以"MM/DD/yyyy"格式为Android生成日期字符串.这是我的代码:

Date d = new Date();
String date = (new SimpleDateFormat("MM/DD/yyyy")).format(d);
Run Code Online (Sandbox Code Playgroud)

它返回以下字符串:

02/32/2011
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?我看不出任何我做错的事.

Mar*_*k B 11

使用"MM/dd/yyyy".您使用的是一年中的一天而不是一个月中的某一天.

http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html


PeS*_*PeS 5

dd是一个月中某天的占位符,而不是DD.