Reputation: 47
In my java project I'm trying to create a timestamp that will be stored later in the database (Oracle Database). After many trials I found that the timestamp my java code generates is in the following format:
2017-06-20 14:38:12.296
and the timestamp format in Oracle is like:
20-JUN-19 02.38.55.059000000 PM
Is there a way to convert the java format of timestamp to oracle's format?
My code for creating the timestamp:
Date date = new Date();
long time = date.getTime();
Timestamp timeStamp = new Timestamp(time);
I have tried so many timestamps conversions but with no use.
Upvotes: 1
Views: 11488
Reputation: 1275
To add from QuaternionsRock's answer, since it's not tested, you can always use DateFormat.
From his link, you can see the following example, which I am able to test with a date such as 20-JUN-19 06.06.05.112 PM.
DateFormat df = new SimpleDateFormat("dd-MMM-yy HH.mm.ss.SSS a");
Date date = df.parse(oracleTS);
Timestamp ts = new Timestamp(date.getTime());
There does not need to be two a
in the DateFormat string, contrary to what is posted in QuaternionsRock' link.
Upvotes: 2
Reputation: 922
From here:
java.sql.Timestamp javaTimeStamp = oracleTimeStamp.timestampValue();
I can't say I've tested it but it seems logical to me.
Upvotes: -1