0

When a String value with fractional seconds is passed to java.sql.Timestamp.valueOf() method , where the fractional seconds length is less than 6, the valueOf method adds trailing zeros which changes the value of the fractional string.

public class TimestampTest {
public static void main(String[] args) {
Timestamp t = Timestamp.valueOf("2005-1-01 10:20:50.11");
}
}

valueOf - returns nano seconds as - 110000000 - which is not the original value.

This should instead add leading zeros as done in case of toString() method.

I am expecting output Just '11' or '000000011'

Can someone tell me if my understanding is right or I am mistaking some where.

2
  • 1
    Seems OK to me, 0.11 seconds is 110000000 nano seconds. Commented Dec 28, 2015 at 10:13
  • 1
    Well, your understanding is wrong. It's a fraction of a second. 0.11 is 0.11, not 0.000000011. Commented Dec 28, 2015 at 10:14

1 Answer 1

2

It is a fraction so function behaves right.

0.11 = 0.110000 not 0.000011

In other words, 0.11 seconds is indeed 110,000,000 nanoseconds.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.