java.time
The java.time classes support nanoseconds resolution, more than enough for microseconds .
The Instant class is the main building block class in java.time, representing the moment on the timeline in UTC with a resolution of up to nanoseconds. This means up to nine digits of decimal. Z at the end is short for Zulu and means UTC.
Instant instant = Instant.parse( "2016-01-12T12:34:56.123456789Z" );
Please note that due to the obsolete implementation of Clock in Java 8, the current moment is fixed only up to a millisecond . Fixed in Java 9 with the new Clock implementation.
Line parsing
As for your mention of boost, ptime, call the boost std::string to_iso_extended_string(ptime) subroutine to generate a string in the standard ISO 8601 format. This string can be parsed as LocalDateTime , as the boost code does not include any offset information -from UTC or time zone.
LocalDateTime ldt = LocalDateTime.parse( "2016-01-12T12:34:56.123456789" ) ;
Parsing a long
If you have a few microseconds as a counter from an early 1970s epoch in UTC format ( 1970-01-01T00:00:00Z ), you can convert it to Instant . The Instant class represents a moment in the UTC timeline with a nanosecond resolution.
The Instant class has convenient static methods for converting from count whole seconds , from the number of whole seconds plus a fractional second in nanoseconds, or from the number of milliseconds . But there are no such methods for counting microseconds or nanoseconds.
As a workaround, we can define a Duration and add it to the reference date of an era already defined as a constant. We can create a Duration as the number of nanoseconds. To get nanoseconds, we multiply your microseconds by a thousand. Pay attention to the use of a 64-bit long , rather than a 32-bit int . Also note the L attached to the integer literal.
long micros = 1_474_457_086_337_977L ; Duration duration = Duration.ofNanos( micros * 1_000L ); Instant instant = Instant.EPOCH.plus( duration );
instant.toString (): 2016-09-21T11: 24: 46.337977Z