newcoder1010 Posted November 1, 2022 Share Posted November 1, 2022 (edited) Hello, I like to add 5 minutes to current system time. After adding 5 minutes to the current time, I like to have a loop which will keep checking until system time has changed to the new time. Lets say now is 11:50:01AM Add 5 minutes to current time. So new time would be 11:55:01AM I like to have a loop which will keep checking if system time is 11:55:01AM. If yes, exit the loop. I started working on it but I am not quit there yet. LocalDateTime timeNow; while(???) { Thread.sleep(6666); timeNow = java.time.LocalDateTime.now(); } Can you help? Edited November 1, 2022 by newcoder1010 Link to comment Share on other sites More sharing options...
newcoder1010 Posted November 1, 2022 Author Share Posted November 1, 2022 I made some progress but not working yet. Its not reaching the block of code inside the loop LocalDateTime timeNow = java.time.LocalDateTime.now(); System.out.println( "timeNow "+ timeNow); LocalDateTime newtime = timeNow.plusMinutes(5); System.out.println( "newtime "+ newtime); Thread.sleep(5000); while(newtime.equals(timeNow)) { Thread.sleep(5000); timeNow = java.time.LocalDateTime.now(); System.out.println( "timeNow "+ timeNow); } System.out.println( "timeNow exited at "+ timeNow); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now