在字符串中获取计时表的时间?

Getting the time of a Chronometer in a String?

我想将 Chronometer 的时间转换成字符串(或者对于这种用途来说字符串是错误的吗?)。

它是如何工作的?

Chronometer mChronometer;
Button button1;
Button button2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mChronometer = (Chronometer) findViewById(R.id.chronometer);

    button1 = (Button) findViewById(R.id.button1);
    button2 = (Button) findViewById(R.id.button2);

    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mChronometer.setBase(SystemClock.elapsedRealtime());
            mChronometer.start();
        }
    });

    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mChronometer.stop();
        }
    });
}

获取 int 中经过的时间,

int elapsed = (int)(SystemClock.elapsedRealtime()-mChronometer.getBase());

将其转换为字符串,然后在文本视图中设置文本

textView.setText(String.valueOf(elapsed));