• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Working with Dates

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
DateFormat.getDateInstance(DateFormat.SHORT,lc);


 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic