private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
this.upDate();
handler.postDelayed(this, 1000);
}
void upDate() {
setTime();
}
};
private void setTime() {
//日期,api 24暂定
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年 MM月 dd日 HH : mm : ss", Locale.getDefault());
String show_timeStr = formatter.format(new Date(System.currentTimeMillis()));
tv_clock1.setText(show_timeStr);
}
handler.postDelayed(runnable, 1000);
handler.removeCallbacks(runnable);
原文:https://www.cnblogs.com/Mr-quin/p/9193654.html