| Author |
Help in using DateFormat
|
Tony Evans
Ranch Hand
Joined: Jun 29, 2002
Posts: 521
|
|
I have a method that will take in a string and convert it into a Date using DateFormat. The problem is that I am not sure what the format the string should take. I used the date : "15-Jul-1999" which through up a java.text.ParseException: Unparseable date: "15-Jul-1999" All I need is the day month and year not the time. Thanks for any help Tony public void setMaturityDate(String date) { DateFormat df = DateFormat.getDateInstance(); try { this.maturityDate = df.parse(date); } catch(ParseException e) { System.out.println("Error "+e); } }
|
 |
Nathaniel Stoddard
Ranch Hand
Joined: May 29, 2003
Posts: 1258
|
|
|
You can read the API docs and see for yourself, but it won't parse that text at all. Read the docs and see what it expects.
|
Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
|
 |
Tony Evans
Ranch Hand
Joined: Jun 29, 2002
Posts: 521
|
|
|
Thanks Nathaniel, where can I get these docs online.
|
 |
yacoob ali
Greenhorn
Joined: Aug 20, 2004
Posts: 5
|
|
Hi Tony, You can try this In the above code you can see after the parsing it gives with the time then you can format the date to whatever format you want. You can also have a look at these links http://java.sun.com/developer/JDCTechTips/2003/tt0624.html#2 http://java.sun.com/docs/books/tutorial/i18n/format/dateFormat.html Hope this helps
|
Sadiq
|
 |
 |
|
|
subject: Help in using DateFormat
|
|
|