Re: java.sql.Timestamp and toString output




"Richard Reynolds" <richiereynolds@xxxxxxxxxxxx> wrote in message
news:2Xm%h.6879$H4.3173@xxxxxxxxxxxxxxxxxxxxxxx

"Lew" <lew@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:N8ednfLah9PRV6DbnZ2dnUVZ_qHinZ2d@xxxxxxxxxxxxxx
Greg B wrote:
On May 5, 10:48 pm, Lew <l...@xxxxxxxxxxxxxxxxxxxx> wrote:
Greg B wrote:
according
tohttp://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html#toString(),
Returns:
a String object in yyyy-mm-dd hh:mm:ss.fffffffff format
however, when I do
import java.sql.Timestamp;
..
Timestamp ts = new Timestamp(1000);
System.out.println("Timestamp.toString(): " + ts.toString());
I get
Timestamp.toString(): 1970-01-01 10:00:01.0 (notice the formatting of
the nanos).
if I were to do ts.setNanos(1), then my output screen would contain
the 01.00000001
Great. You verified the Javadocs. Looks like they were right.

--
Lew

How's 10:00:01.0 in hh:mm:ss.fffffffff format?

As I understand that format string, it indicates that up to nine (?)
fractional digits will show, but it is usual in formatted output to show
fewer fractional digits when that is sufficient to represent the value.
I see no problem.

--
Lew

so does it do: 10:00:01.1 or 10:00:01.00000001 like the OP claimed?

just tried it, first thing to note is they're not nanos, the way the
original poster constructed it they're millis, but for 2 timestamps created
using 1000 and 1001 millis:
Timestamp.toString(): 1970-01-01 01:00:01.0

Timestamp.toString(): 1970-01-01 01:00:01.001

so, yes, inconsistency abounds!

if I do setNanos(0) and setNanos(1) on the same timestamp:

Timestamp.toString(): 1970-01-01 01:00:01.0

Timestamp.toString(): 1970-01-01 01:00:01.000000001

so again, inconsistent, bug I'd say.





.