Reputation: 544
I'm a novice in Java programming and I wanted to implement the timer class in my program. I'm making a mini time-based testing system which outputs a question then time remaining and then the answer choices Example:
A. % B./ C. * D. None of the above
A. \r B. \t C. \n D. \
I don't know how to get that time remaining part. It's supposed to run in background and change right when the next question comes up
Upvotes: 0
Views: 64
Reputation: 7042
You can accomplish what you're trying to do without using timer, which will probably be easier, as you're new.
There's a function called System.currentTimeMillis()
that returns the current system time in milliseconds. From that, you can:
As such:
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
// Do other stuff...
long stopTime = System.currentTimeMillis();
int elapsedSeconds = (int)((stopTime - startTime) / 1000);
System.out.println(elapsedSeconds + " seconds elapsed");
}
Upvotes: 1