作者:碳酸钙baby_849 | 来源:互联网 | 2022-12-18 05:09
1> AxelH..:
作为替代方案,我会用它String.format
来创建它String
return String.format("%d/%d/%d", day, month, year)
你想用前导零来格式化你的日期吗?格式化程序很容易:
return String.format("%02d/%02d/%02d", day, month, year)
- 0 - use leading zero instead of spaces.
- 2d - Minimum two character to print (so "2" will use " 2")
您可以在Formatter中找到有关允许的标志的完整文档
一个简单的例子:
String.format("%002d", 5);
005
和日期的例子,
String.format("%02d/%02d/%02d", 9, 5, 18);
18年9月5日