Duaration Time Add

Run Settings
LanguageJava
Language Version
Run Command
import java.time.Duration; import java.time.LocalTime; import java.util.Random; class Main { static final int HOUR_LOW = 1; static final int HOUR_HIGH = 24; static final int MINUTE_LOW = 1; static final int MINUTE_HIGH = 60; public static void main(String[] args) { Random r = new Random(); Duration d = Duration.ZERO; for (int i = 1; i <= 10; i++) { String time = String.format("%02d:%02d", r.nextInt(HOUR_HIGH - HOUR_LOW) + HOUR_LOW, r.nextInt(MINUTE_HIGH - MINUTE_LOW) + MINUTE_LOW); System.out.println(time); d = d.plus(Duration.between(LocalTime.MIDNIGHT, LocalTime.parse(time))); } System.out.println("Total duration: " + d); long hours = d.toHours(); int minutes = (int) ((d.getSeconds() % (60 * 60)) / 60); int seconds = (int) (d.getSeconds() % 60); System.out.println(hours + ":" + minutes + ":" + seconds); } }
Editor Settings
Theme
Key bindings
Full width
Lines