Java parse oracle timestamp to date.util.date

16,430

Solution 1

You shouldn't have to parse anything. Use one of the ResultSet.getTimestamp() methods, and you'll have a java.sql.Timestamp object directly, which extends java.util.Date.

java.sql.Timestamp ts = myResultSet.getTimestamp( … );

And this will have the additional advantage of being portale across databases and locales.

Solution 2

"yy-MM-dd"?

"01-MAY-12"

Is your day number really "12" and your year "01"?

And how come your error shows "2012-5-1.13.0. 47. 0", which is presumably a date in yet another format?

Share:
16,430
danarj
Author by

danarj

Updated on June 04, 2022

Comments

  • danarj
    danarj almost 2 years

    i want to parse oracle timestamp (01-MAY-12 01.00.47.000000000 PM) to java.util.Date i used this:

    Date dateStart=new SimpleDateFormat("yy-MM-dd HH:mm:ss.S").parse("01-MAY-12 01.00.47.000000000 PM");
    

    but i get this error

    java.text.ParseException: Unparseable date: "2012-5-1.13.0. 47. 0"