我有一个倒数计时器,它显示从60到0的秒数(1分钟倒数计时器)。当达到1位数字(例如9,8,7 ..)时,它显示9而不是09。我尝试使用String.format("%[B]02d[/B]", x);
将x从long转换为string的位置。没用
我想要一个相当于 String.format("%2d", 1)
您可以使用DecimalFormat完成它:
NumberFormat f = new DecimalFormat("00");
long time = 9;
textView.setText(f.format(time));
输出:
09
或者,您也可以使用String.format():
String format = "%1$02d"; // two digits
textView.setText(String.format(format, time));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句