Time Duration Add Time

Run Settings
LanguageJava
Language Version
Run Command
import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalTime; import java.util.Random; class Main { public static void main(String[] args) { DecimalFormat myformatTime = new DecimalFormat("00"); SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm"); Random r = new Random(); int Low1 = 1; int High1 = 24; int Low2 = 1; int High2 = 60; int Result1 = 0; int Result2 = 0; String wauxTime = "00:00"; String[] fields1; Duration d1 = Duration.ZERO; //Duration.ofSeconds(0) < Duration d2 = null; for (int i = 1; i <= 10; i++) { Result1 = r.nextInt(High1 - Low1) + Low1; Result2 = r.nextInt(High2 - Low2) + Low2; wauxTime = myformatTime.format(Result1)+":"+myformatTime.format(Result2); fields1 = wauxTime.split(":"); // d1 = Duration.parse(String.format("P%dM%sS", Double.parseDouble(fields1[0]),fields1[1])); d2=Duration.between(LocalTime.MIDNIGHT, LocalTime.parse(wauxTime)); d1=d2; // d2=d1.ofSeconds(seconds).plusHours(hours).plusMinutes(minutes) ? // d3 = d1.plus(d2); System.out.println(d2.toString()); } } }
Editor Settings
Theme
Key bindings
Full width
Lines