Created
December 18, 2018 12:15
-
-
Save nirodg/d87840a04e3925757a34395fa05eb4c0 to your computer and use it in GitHub Desktop.
Wait for X minutes and seconds then it stops.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int minute = 0, seconds = 30, waitingTime = 2; | |
Calendar currTime = Calendar.getInstance(); | |
Calendar timeSleep = (Calendar) currTime.clone(); | |
timeSleep.add(Calendar.MINUTE, minute); | |
timeSleep.add(Calendar.SECOND, seconds); | |
System.out.println(String.format("Now is %s:%s and I will wait until %s:%s", currTime.get(Calendar.MINUTE), currTime.get(Calendar.SECOND), | |
timeSleep.get(Calendar.MINUTE), timeSleep.get(Calendar.SECOND))); | |
while (currTime.before(timeSleep)) { | |
System.out.println(String.format("%s:%s", currTime.get(Calendar.MINUTE), currTime.get(Calendar.SECOND))); | |
Thread.sleep(waitingTime * 1000); | |
currTime.add(Calendar.SECOND, waitingTime); | |
} | |
System.out.println("Done!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment