int month = 6;
Log.i(TAG, "month :" + month );
String str_month = String.format("%02d", month);
Log.i(TAG, "str_month :" + str_month );
输出:
month :6
str_month :06
本文介绍了一种将整数格式化为两位数字符串的方法,并通过实例演示了如何使用 Java 的 String.format 方法来实现这一功能。具体步骤包括定义一个整数变量、使用 String.format 将其转换为两位数字符串并输出。
int month = 6;
Log.i(TAG, "month :" + month );
String str_month = String.format("%02d", month);
Log.i(TAG, "str_month :" + str_month );
输出:
month :6
str_month :06

被折叠的 条评论
为什么被折叠?