When I run this piece of code, I get the following exception.
java.lang.IllegalArgumentException: Cannot format given Object as a Date at java.text.DateFormat.format(DateFormat.java:279) at java.text.Format.format(Format.java:133) at Date.formatDate(Date.java:27) at Date.main(Date.java:37)
Could somebody help me with this please??
SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Joined: Jan 29, 2003
Take a look at the signatures on DateFormat. There are some that take a String argument like your "2005-02-10" and return a Date object. And Date is just what the format method expects as an argument. So you need a two step process:
String YYYY-MM-DD -> Date -> String MEDIUM
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Dec 13, 2004
Hi Jayashree, The following code can solve your problem:-