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 Working with Dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Working with Dates" Watch "Working with Dates" New topic
Author

Working with Dates

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 582
I am writing a web appliction which takes in a date in the format of 02/05/2004.
I need to format the date and then insert it into an Oracle DataBase which takes Dates in the format of 02/May/2004.
I am not sure of hwo to write the code but this is my effort:
String aDate = "02/04/2004";
String formattedDate = null;
DateFormat dateFormatter;
Locale lc = Locale.UK;

Date date = null;

dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,lc);
try
{
date = dateFormatter.parse(aDate);
System.out.println(date.toString());
}
catch(ParseException e)
{
System.out.println("Date Exception "+e);
}
It return an exception Date Exception java.text.ParseException: Unparseable date: "02/04/2004"
Thansk for any help.
Tony
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
try
DateFormat.getDateInstance(DateFormat.SHORT,lc);

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 582
Thanks that worked, I have decided to go rfor the Oracle solution though and translate and compare the date within a store procedre.
If anyone is interested this store procedure will take a string in of type 02-04-2004
and will translate it into 02-APR-2004.
CREATE OR REPLACE procedure TC_DATE(adate IN VARCHAR2)
IS
BEGIN
insert into DateTest values(TO_DATE(adate,'DD-MM-YYYY'));
END;
/
Thanks again for your help.
Tony
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working with Dates