Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need assistance with DateTime conversion

843840Mar 22 2002 — edited Mar 22 2002
I want to use the session.getCreationTime() value and write it to an Oracle Date field.

I am having trouble getting the value in the proper type and format.

I have a test servlet to try to understand the various ways to use and convert DateTime values.

Here's the code:

response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();

HttpSession session = request.getSession();
long logontime = session.getCreationTime();
SimpleDateFormat formatter = new SimpleDateFormat("mm-dd-yyyy hh:mm:ss");
java.sql.Date sqlDate = new java.sql.Date(logontime);
String sDate = formatter.format(sqlDate);

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("DateTime in Milliseconds: " + session.getCreationTime() + "<br>");
out.println("DateTime as java.sql.Date: " + sqlDate + "<br>");
out.println("java.sql.Date SimpleDateFormat: " sDate "<br>");
out.println("</body>");
out.println("</html>");
out.close();



Here's the output:

DateTime in Milliseconds: 1016812138284
DateTime as java.sql.Date: 2002-03-22
java.sql.Date SimpleDateFormat: 48-22-2002 10:48:58

What's happening with the Month is the SimpleDateFormat output?

Also,

How can I convert this string into a valid Date Object to use in CallableStatement.setDate(int index, Date x)?

Thank you for your help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2002
Added on Mar 22 2002
4 comments
301 views