Skip to Main Content

Java Programming

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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Convert String to java UTC date then to sql date

807603Oct 17 2007 — edited Oct 17 2007
Hi,

I am trying to convert string (MM/dd/yyyy format) to UTC date time and store in the database.

This is what I did:

String dateAsString = "10/01/2007";

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
formatter.setLenient(false);
java.util.date dateValue = formatter.parse(dateAsString, new ParsePosition(0));

dateValue will be Sun Sep 30 20:00:00 EDT 2007 in UTC.

Now I need to store this date and time to MS SQL database.
I used the following code:
java.sql.Date sqlDateValue = new java.sql.Date(parsedToDate.getTime());

But this code give only the date, not time 2007-09-30

Can anybody tell me how I can change this java date to sql date (or datetime?) so that I can get both date and time.

Thanks,
semaj
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 14 2007
Added on Oct 17 2007
1 comment
5,227 views