我想显示持续运行的时间,但此代码仅显示应用程序启动的时间。
TextView textView = (TextView) findViewById(R.id.textView);
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
textView.setText(currentDateTimeString);
最佳答案
您可以使用处理程序来完成此操作,如下所示:
new Handler().postDelayed(new Runnable() {
public void run() {
// display your time here...
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
textView.setText(currentDateTimeString);
}
}, 1000); // here 1 seconds to refresh time after 1 seconds
关于android - 如何显示实时运行的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56809811/