Here you can find the source of reportTimeDiff(LocalTime start, LocalTime end)
Parameter | Description |
---|---|
start | staring LocalTime |
end | ending LocalTime |
public static void reportTimeDiff(LocalTime start, LocalTime end)
//package com.java2s; //License from project: Open Source License import java.time.LocalTime; import static java.lang.Math.pow; public class Main { /**//from w ww. j a va 2s . c om * This method will print (to System.out) the difference * in time between a starting and an ending time * * @param start staring LocalTime * @param end ending LocalTime */ public static void reportTimeDiff(LocalTime start, LocalTime end) { end = end.minusHours(start.getHour()); end = end.minusMinutes(start.getMinute()); end = end.minusSeconds(start.getSecond()); end = end.minusNanos(start.getNano()); System.out.print("Computed in "); if (end.getHour() != 0) { System.out.print(end.getHour() + " Hours, "); } if (end.getMinute() != 0) { System.out.print(end.getMinute() + " Minutes, "); } if (end.getSecond() != 0 || end.getNano() != 0) { int nanos = (int) (end.getNano() / pow(10, 4)); System.out.print(end.getSecond() + "." + nanos + " Seconds"); } else { System.out.print("less than 0.001 second"); } } }