Skip to content

Instantly share code, notes, and snippets.

@nirodg
Created December 18, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirodg/d87840a04e3925757a34395fa05eb4c0 to your computer and use it in GitHub Desktop.
Save nirodg/d87840a04e3925757a34395fa05eb4c0 to your computer and use it in GitHub Desktop.
Wait for X minutes and seconds then it stops.
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