Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
–
–
–
–
–
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.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.