cancel
Showing results for 
Search instead for 
Did you mean: 

Converitng SQL Anywhere's datetime value into java.Util.Date

Former Member
4,080

Hi,

I am exporting the data of any table in which there is field like CREATED_ON whoese datatype is date time.

While exporting value of the field is 2013-11-18 15:37:47.123 When I am going to convert the above value into java.Util.Date. I am writing following

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
date = formatter.parse(columnValue);
System.out.println("yyyy-MM-dd HH:mm:ss "+date);

Error is coming due to "15:37:47.123" format malformed. Because extra value ".123" after HH:mm:ss is giving error. When I remove the extra ".123" error is gone.

So any one tell what is this extra value and how can I parse it in same format by giving correct date format.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

This is solution what I got...

String columnValue="2013-11-18 15:37:47.000";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date;
date = formatter.parse(columnValue);

Answers (1)

Answers (1)

Former Member

I've had the same problem, and it's even more complex because you forgot that a time zone might also be involved.

Here is my potential solution, in another answered question: JDBC Retrieving timestamp with Time Zone