File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Help in using DateFormat Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Help in using DateFormat" Watch "Help in using DateFormat" New topic
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Help in using DateFormat
 
Similar Threads
how to convert Julian Date into Calendar Date
Convert the String to date format
java(DATE)Validation
Unable to get Date instance in a particular format
simple date format