I am trying to compare user defined time in format HH:MM with current time in an infinite loop. When they are equal, some action should occur.
I have used following code
This is OPs(*) fixed code following Tobías's instructions:
//get user time and current time
String time = jFormattedTextField1.getText();
LocalTime userTime1 = LocalTime.parse(time);
LocalTime timeNow = LocalTime.now().truncatedTo(ChronoUnit.SECONDS);
//calculate the diff in seconds
int timeDur = (int)Duration.between(timeNow, userTime1).getSeconds();
//start the timer object using this difference
Countdown countdown = new Countdown (timeDur);
(*) Extracted from the edited question, because it doesn't belong there (see this meta discussion)