Reputation: 11050
I want to show a date string in this format: Jun 27, 2012
. I did this:
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyy");
String date = sdf.format(Calendar.getInstance());
But it gives me this:
java.lang.IllegalArgumentException: Cannot format given Object as a Date
What am I doing wrong?
Upvotes: 1
Views: 1039
Reputation: 4690
You can not use Calendar.getInstance()
, since the param for same is date and not calender instance. Just change the param to getTime()
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
String date = sdf.format(Calendar.getInstance().getTime());
Upvotes: 9