需要在计时器上获得其他价值

时间:2013-12-05 16:15:28

标签: android timer

我有代码:

TextView txtCurrentTime = (TextView)findViewById(R.id.textClock);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = (hours + 4) + ":" + minutes + ":" + seconds;
txtCurrentTime.setText(curTime);

关于输出我得到:

  

1:2:1

但我需要得到:

  

1时02分01秒

我如何才能获得这个价值?

1 个答案:

答案 0 :(得分:1)

更改:

String curTime = (hours + 4) + ":" + minutes + ":" + seconds;

with:

String curTime = String.format("%02d:%02d:%02d", (hours + 4), minutes, seconds);

有关它的更多信息:public static String format (String format, Object... args)