Fork me on GitHub
#java
<
2023-01-20
>
mjw17:01:56

I’m trying to find good documentation that explains why DateTimeFormatter.ISO_LOCAL_DATE_TIME strips zeros off of millisecond/nanosecond values in Java 8 - 18? For example, 2023-01-20T10:39:00.370 is formatted as 2023-01-20T10:39:00.37 . If I then parse that back using the same formatter, it again is represented as 370 milliseconds. As far as I can tell, the first three digits are assumed to represent milliseconds; the second three, microseconds; and the final three, nanoseconds. So, if I’m reading/understanding correctly, 37 represents 370 because the final zero is implied (and 037 would be used for 37ms)?

hiredman17:01:06

it is a fraction of a second

hiredman17:01:47

the first 3 digits are "milliseconds" because 1000 milliseconds is a second, and the first 3 digits after a decimal are tenths, hundredths, thousandths

hiredman17:01:56

a millisecond is 1e-3 and microseconds are 1e-6

hiredman17:01:31

so those units just happen to match up with decimal places when dealing with seconds, but it isn't like the format is {seconds}.{milliseconds}{microseconds}

hiredman17:01:45

the format is {seconds}.{fraction-of-seconds}

mjw17:01:37

Thanks! That makes sense. I don’t know why I didn’t make that connection.