java - Timestamp in ISO 8601 - the last 6 digits yyyy-MM-dd'T'HH:mm:ss.? -


i have timestamps looking this:

    2015-03-21t11:08:14.859831     2015-03-21t11:07:22.956087 

i read wiki article on iso 8601, did not meaning of last 6 digits here.

i tried getting down milliseconds using "yyyy-mm-dd't'hh:mm:ss.sss" or "yyyy-mm-dd't'hh:mm:ss.ssssss". more precise milliseconds - microseconds?

is more precise milliseconds?

yes, it's microseconds in case.

iso-8601 doesn't specify maximum precision. states:

if necessary particular application decimal fraction of hour, minute or second may included. if decimal fraction included, lower order time elements (if any) shall omitted , decimal fraction shall divided integer part decimal sign specified in iso 31-0, i.e. comma [,] or full stop [.]. of these, comma preferred sign. if magnitude of number less unity, decimal sign shall preceded 2 zeros in accordance 3.6.

the interchange parties, dependent upon application, shall agree number of digits in decimal fraction. [...]

(you actually see comma decimal separator - @ least, that's experience.)

unfortunately in experience, parsing value in java 7 tricky - there isn't format specifier "just consume fractional digits , right thing". may find need manually chop trailing 3 digits off before parsing milliseconds.

as java 8 supports precision of nanoseconds, it's rather simpler - , in fact, built-in iso formatter can parse fine:

import java.time.*; import java.time.format.*;  public class test {     public static void main(string[] args) {         datetimeformatter formatter = datetimeformatter.iso_date_time;         system.out.println(localdatetime.parse("2015-03-21t11:07:22.956087", formatter));      } } 

Comments