Timer:
Time is really easy to keep track off.
Use the code:
System.currentTimeMillis(); gets the current system time in milliseconds.
It is such a big number its a long. (remember like double, but holds
more places).
So we might say as a global:
long originalTime=System.currentTimeMillis();
And then to find how many milliseconds have passed we could say:
int milliseconds = (int) (System.currentTimeMillis()-originalTime);
Or to find how many seconds have passed we could say:
int seconds = (int) ((System.currentTimeMillis()-originalTime)/1000);
Or to find how many seconds to the tenths place (ie 23.4 seconds) have passed we could say:
double seconds = (int) ((System.currentTimeMillis()-originalTime)/100.0)/10.0;
|