Simple Date Format - milliseconds with more precision

B

brisco5

I'm using a UDB database, where the timestamp of a Date field returns
me dates with milliseconds up to 6 decimals:
2005-02-25 11:50:11.579411

I'm looking for two possible ways to deal with time stamp.
1. I've tried creating a Simple Date Format object with this time
stamp, but I don't know how to save the milliseconds with all 6 digits.
I can store up to 3 ("SSS"), but no more than that
Tried:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss.SSSSSS");
but that causes havoc.

2. Write a query that'll truncate the time stamp and lop off the final
3 digits. This query would need to be basic enough to work in MSSQL,
Oracle, and UDB without any modifications.

Any ideas?
 
W

Wiseguy

(e-mail address removed) scribbled on the stall wall:
I'm using a UDB database, where the timestamp of a Date field returns
me dates with milliseconds up to 6 decimals:
2005-02-25 11:50:11.579411

I'm looking for two possible ways to deal with time stamp.
1. I've tried creating a Simple Date Format object with this time
stamp, but I don't know how to save the milliseconds with all 6 digits.
I can store up to 3 ("SSS"), but no more than that

Probably because if there are six decimal places then they are not
milliseconds. Milliseconds only have three decimal places to the right
of the decimal in seconds...so, if you can store SSS to three places then
you ARE, in fact storing precision up to the nearest millisecond.

2005-02-25 11:50:11.579411

is 11 seconds and 579 milliseconds

Also be advised that the resolution of the system clock is determined
by hardware and operating system. You may find that all those extra
digits are meaningless based on your hardware and OS.
 
W

Wiseguy

(e-mail address removed) (Wiseguy) scribbled on the stall wall:
(e-mail address removed) scribbled on the stall wall:

BTW: if ALL you want to do is store the value of the timestamp (as returned
from the database) then convert it to a string and save the string
representation of the timestamp.

Then you can write whatever parsing algorithms you like to grab components
of the stamp.
 
S

Steve W. Jackson

[email protected] (Wiseguy) said:
(e-mail address removed) scribbled on the stall wall:

Probably because if there are six decimal places then they are not
milliseconds. Milliseconds only have three decimal places to the right
of the decimal in seconds...so, if you can store SSS to three places then
you ARE, in fact storing precision up to the nearest millisecond.

2005-02-25 11:50:11.579411

is 11 seconds and 579 milliseconds

Also be advised that the resolution of the system clock is determined
by hardware and operating system. You may find that all those extra
digits are meaningless based on your hardware and OS.

Why do you assume that the decimal portion is milliseconds when it
contains 6 digits of precision? To me, that says that it goes beyond
milliseconds to even finer precision. Admittedly, though, not many
systems can go beyond milliseconds in their timekeeping precision.

Either way, you should simply be able to grab those digits beyond the
decimal and work with them. That's either .579411 seconds, or you could
treat it as 579.411 milliseconds, or something along those lines. It's
just a matter of deciding to keep or discard the additional precision
digits, and then deciding what to do with it if it's discarded
(rounding, truncation, etc.).

= Steve =
 
R

Richard Wheeldon

I'm using a UDB database, where the timestamp of a Date field returns
me dates with milliseconds up to 6 decimals:
2005-02-25 11:50:11.579411

That's not milliseconds - it's microseconds.
java.sql.Timestamp handles times with nanosecond precision, but
you might have to write your own string parser.

Richard
 
L

Lee Fesperman

Richard said:
That's not milliseconds - it's microseconds.
java.sql.Timestamp handles times with nanosecond precision, but
you might have to write your own string parser.

Yep, you'll have to write your own. SimpleDateFormat won't truncate microsecond,
nanosecond, ... digits even with setLenient(true).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top