Formatting Java Instant for resolutions

Sat, Jun 9, 2018

I have had to look up how to format Java’s Instant with a given resolution - for example in microseconds or nanoseconds. After fiddling with various formatters, I was happy to finally get this right.

public void shouldFormatWith7Decimals() {
  int resolution = 7;
  DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
  Instant instant =;