Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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.

like image 397
Russell Stewart Avatar asked Feb 22 '26 06:02

Russell Stewart


1 Answers

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

like image 84
Mark B Avatar answered Feb 23 '26 20:02

Mark B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!