Jump to content

How to add 5 minutes to current time


newcoder1010
 Share

Recommended Posts

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 by newcoder1010
Link to comment
Share on other sites

  • newcoder1010 changed the title to How to add 5 minutes to current time

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...