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
bit inconsistent though isn't it, if it was being treated as a numeric value
you'd expect
0 or 1
if it was being treated as a formatted string for output you'd expect
00000000 or 00000001
I don't see why it would do 0 in one case and 00000001 in another
disclaimer - I haven't tried it myself ...
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?
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.
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html#toString()
toString
public String toString()Formats a timestamp in JDBC timestamp escape
format. yyyy-mm-dd hh:mm:ss.fffffffff, where ffffffffff indicates
nanoseconds.
The constructor takes a single long that says it specifies the time in
millis and when I only use that I get a telltale 3 places after the seconds
(if it's not 0):
Timestamp.toString(): 1970-01-01 01:00:01.0
Timestamp.toString(): 1970-01-01 01:00:01.001
However if I do a setNanos(0) and setNanos(1) on it then I get a telltale 9
places:
Timestamp.toString(): 1970-01-01 01:00:01.0
Timestamp.toString(): 1970-01-01 01:00:01.000000001
so I'm guessing that if you don't explicitly set the nanos it acts as if
it's got millis only, and it certainly does the formatting differently
depending on if it's 0 or not in either case.
As you should.
> However if I do a setNanos(0) and setNanos(1) on it then I get a telltale 9
> places:
> Timestamp.toString(): 1970-01-01 01:00:01.0
> Timestamp.toString(): 1970-01-01 01:00:01.000000001
>
Again, as you should.
> so I'm guessing that if you don't explicitly set the nanos it acts as if
> it's got millis only, and it certainly does the formatting differently
> depending on if it's 0 or not in either case.
The precise description would be ss.fffffffff indicate the seconds.
I guess, it is implicitly understood in the documentation that the
format fffffffff
behaves as fractional one (implying a standard behaviour for
fractional digits).
Regards,
Faton Berisha