Possible Duplicate:
How to convert milliseconds to “hh:mm:ss” format?
I bet many people need a timer consisting of: minutes : seconds : hundreds of seconds
.
Clearly you start with:
` public TimeGame(){
timer = new Timer(10, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
counter++;
}
});
timer.start();
}`
And then you need to call a methode that transforms this counter in : minutes : seconds : hundreds of seconds
.
`private String timeTransfer(){
minutes = counter/6000;
counter = counter - (minutes*6000);
seconds = counter/100 ;
counter = counter - (seconds*100);
milliseconds = counter;
return minutes + " : " + seconds + " : " + miliseconds;
}`
Yet i have a bug in my method. once it reaches 100 milliseconds it jumps back to 0.
Normally it would have to put 0:1:0
, but it jumps back to 0:0:0
.
all Variables are declared private in the class.
So my question is does someone know a better method?