email me at borlaj@portlandschools.org

Loading
notes previous (10/<10) submit the dump links  
 

Time

 

Time is super easy in java. We need to get the time from the system clock. Which we do below:

 

long startTime = System.currentTimeMillis();

Now anywhere, we want to know how much time has passed:

long elapsedTimeMillis = System.currentTimeMillis()-startTime;

That gives us time in milliseconds. Now if we want to get time in seconds, we might say:

double elapsedTimeSec = elapsedTimeMillis/1000.0;
int elapsedTimeRoundedSec=(int)(Math.round(elapsedTimeMillis/1000.0)); //this is rounded