开发者

SimpleDateFormat in Android giving current date as 02/32/2011

开发者 https://www.devze.com 2023-02-08 02:46 出处:网络
Today is February 1, 2011. I am trying to generate a date string for Android in the format \"MM/DD/yyyy\" using SimpleDateFormat. Here is my code:

Today is February 1, 2011. I am trying to generate a date string for Android in the format "MM/DD/yyyy" using SimpleDateFormat. Here is my code:

Date d = new Date();
String 开发者_JAVA技巧date = (new SimpleDateFormat("MM/DD/yyyy")).format(d);

It returns the following string:

02/32/2011

What is going on here? I can't see anything that I'm doing wrong.


Use "MM/dd/yyyy". You're using the day in year instead of day in month.

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


dd is placeholder for day of month, not DD.

0

精彩评论

暂无评论...
验证码 换一张
取 消