• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help in using DateFormat  RSS feed

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathaniel, where can I get these docs online.
 
yacoob ali
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!