|
|
||||||
|
#1
|
|
|
|
|
according to http://java.sun.com/j2se/1.5.0/docs/...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 |
|
|
|
#2
|
|
|
|
|
Greg B wrote:
> according to [..]), > > 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. |
|
#3
|
|
|
|
|
"Lew" <lew> wrote in message
news:nz2d > Greg B wrote: > > 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 ... |
|
#4
|
|
|
|
|
On May 5, 10:48 pm, Lew <l> wrote:
> Greg B wrote: >> >> > > Great. You verified the Javadocs. Looks like they were right. > > -- > Lew How's 10:00:01.0 in hh:mm:ss.fffffffff format? |
|
#5
|
|
|
|
|
Greg B wrote:
> On May 5, 10:48 pm, Lew <l> wrote: > > 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. |
|
#6
|
|
|
|
|
"Lew" <lew> wrote in message
news:nz2d > Greg B wrote: > > 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? |
|
#7
|
|
|
|
|
"Richard Reynolds" <richiereynolds> wrote in message
news:3173 > > "Lew" <lew> wrote in message > news:nz2d > > 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. |
|
#8
|
|
|
|
|
what documentation have you been looking at, my friend. what millis?
http://java.sun.com/j2se/1.5.0/docs/...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. |
|
#9
|
|
|
|
|
"Greg B" <russiandevil> wrote in message
news:3000 > what documentation have you been looking at, my friend. what millis? > > [..]) > > toString > public String toString()Formats a timestamp in JDBC timestamp escape > format. yyyy-mm-dd hh:mm:ss.fffffffff, where ffffffffff indicates > nanoseconds. > Same docs Greg however I'm reading between the lines a bit! think they may have left a bit out of the toString description. 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. |
|
#10
|
|
|
|
|
On May 7, 1:04 am, "Richard Reynolds" <richiereyno>
wrote: > 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 > 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 |
|
|
| Similar Threads | |
| Double.toString from Java to C# What is the equivalent of Double.toString from Java in C# In Java new Double(4).toString() = "4.0" but in C# new Double(4).ToString() = "4" |
|
| Java Timestamp in SQL // DO NOT DO THIS! // BUG: loses time of day preparedStatement.setDate(1, new java.sql.Date(date.getTime())); // DO THIS preparedStatement.setTimestamp(1,... |
|
| equivelant of Java's toString() method? (not repr) Pretty simple seeming question, but can't find answer via google or docs... I am using urllib2 as follows: handle = urlopen(req, postdata) # and URL to return a... |
|
| Retrieving timestamp output parameter from SqlCommand I've got a SqlCommand that executes a SQL Server 2000 stored procedure which, among other things, returns a timestamp output parameter. For the life of me, I can't figure... |
|
| equivalent to Java's toString()? What is the python equivalent to java's toString()? When debugging I want to be able to basically be able to do this: print MyObjectInstance or print... |
|
|
All times are GMT. The time now is 09:43 AM. | Privacy Policy
|