作者:pan2502851807 | 2023-09-07 21:03
1> tiny sunligh..:
public long startTime = 0;
public void startTimer(View view) {
Timer stopwatchTimer = new Timer();
startTime = System.currentTimeMillis();
stopwatchTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView timerTextView = (TextView) findViewById(R.id.runningTimer);
timerTextView.setText(stopwatch());
}
});
}
}, 0, 10);
}
// Returns the combined string for the stopwatch, counting in tenths of seconds.
public String stopwatch() {
long nowTime = System.currentTimeMillis();
long cast = nowTime - startTime;
Date date = new Date(cast);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss.S");
return simpleDateFormat.format(date);
}