import java.time.Duration;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.temporal.ChronoUnit;
class TesteDurationNovo {
public static void main
(String[] args
) {
LocalDateTime primeiraData = LocalDateTime.of(2017, Month.JANUARY, 10, 14, 00, 00);
LocalDateTime segundaDate = LocalDateTime.of(2016, Month.JANUARY, 10, 16, 30, 00);
Duration testeDuration = Duration.between(primeiraData, segundaDate);
long dias = testeDuration.toDays();
Duration d2 = testeDuration.minus(dias, ChronoUnit.DAYS);
long horas = d2.toHours();
Duration d3 = d2.minus(horas, ChronoUnit.HOURS);
long minutos = d3.toMinutes();
Duration d4 = d3.minus(minutos, ChronoUnit.MINUTES);
long segundos = d4.getSeconds();
Duration d5 = d4.minus(segundos, ChronoUnit.SECONDS);
long nanos = d5.toNanos();
Duration d6 = d5.minus(nanos, ChronoUnit.NANOS);
System.
out.
println("Total: " + dias
+ " dias, " + horas
+ " horas, " + minutos
+ " minutos, " + segundos
+ " segundos, " + nanos
+ " ns."); System.
out.
println("Resultado: " + testeDuration.
toString()); if (!d6.isZero()) throw new AssertionError(d6.toString());
}
}
aW1wb3J0IGphdmEudGltZS5EdXJhdGlvbjsKaW1wb3J0IGphdmEudGltZS5Mb2NhbERhdGVUaW1lOwppbXBvcnQgamF2YS50aW1lLk1vbnRoOwppbXBvcnQgamF2YS50aW1lLnRlbXBvcmFsLkNocm9ub1VuaXQ7CgpjbGFzcyBUZXN0ZUR1cmF0aW9uTm92byB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgogICAgICAgIExvY2FsRGF0ZVRpbWUgcHJpbWVpcmFEYXRhID0gTG9jYWxEYXRlVGltZS5vZigyMDE3LCBNb250aC5KQU5VQVJZLCAxMCwgMTQsIDAwLCAwMCk7CiAgICAgICAgTG9jYWxEYXRlVGltZSBzZWd1bmRhRGF0ZSA9IExvY2FsRGF0ZVRpbWUub2YoMjAxNiwgTW9udGguSkFOVUFSWSwgMTAsIDE2LCAzMC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