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.

asked 25 Nov '13, 05:27

Rajeev's gravatar image

Rajeev
115369
accept rate: 100%

edited 25 Nov '13, 09:11

Mark%20Culp's gravatar image

Mark Culp
23.3k9132274

1

Which driver are you using to fetch the data from the server and what data type are you fetching the datetime value as? In other words, are you using jConnect or the SQL Anywhere JDBC Driver and are you fetching the datetime value using getString(), getTimestamp(), ...? If you are using the SQL Anywhere JDBC Driver and you fetch using getTimestamp() then you should be able to convert the java.sql.Timestamp value to a java.util.Date value without issue. If you are fetching as string and have to continue doing so, then you might want to consider temporarily setting the timestamp_format option to not include the fractional seconds when fetching the datetime value. See the documentation on timestamp_format database option. Make sure you use SET TEMPORARY OPTION to when changing the timestamp_format so that you do not mess up other connections.

(25 Nov '13, 08:51) Karim Khamis

I am using jconn4 driver to connect the SQL Anywhere and the datatype is datetime. I am making connection using mybatis api so whenever it fetch the data it treat it as util.Date by default and as it is write in csv so when i will read it, it is a string and I want to convert it into util.Date

By the way I got solution for the same.

(27 Nov '13, 04:14) Rajeev
Replies hidden
1

By the way I got solution for the same.

Feel free to tell more about that solution, in case you expect others could learn from that, too:)

(27 Nov '13, 05:27) Volker Barth
Comment Text Removed

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);
permanent link

answered 05 Dec '13, 07:24

Rajeev's gravatar image

Rajeev
115369
accept rate: 100%

edited 05 Dec '13, 07:44

Volker%20Barth's gravatar image

Volker Barth
31.3k312458674

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

permanent link

answered 01 Dec '13, 17:27

Jonathan%20Baker's gravatar image

Jonathan Baker
1961211
accept rate: 22%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×65
×15
×3

question asked: 25 Nov '13, 05:27

question was seen: 1,643 times

last updated: 05 Dec '13, 07:44