{0:D2}
:前面的0代表的是序号。
D表示的是10进制。
2代表的是小数点第2位开始4舍5入。
例如
int a=1;int b=2;int c=3;int e=5;
float d=4.4;
Debug.log(
string.Format("{0:D}:{1:D}:{2:D}:{3:D}.{4:D}", a, b, c, (int)d, e)
);
显示结果:1:2:3:4.5;
-----------
参考资料3里面,
6、日期格式化
string.Format("{0:d}",System.DateTime.Now) 结果为:2009-3-20 (月份位置不是03)
string.Format("{0:D}",System.DateTime.Now) 结果为:2009年3月20日
string.Format("{0:f}",System.DateTime.Now) 结果为:2009年3月20日 15:37
string.Format("{0:F}",System.DateTime.Now) 结果为:2009年3月20日 15:37:52
string.Format("{0:g}",System.DateTime.Now) 结果为:2009-3-20 15:38
string.Format("{0:G}",System.DateTime.Now) 结果为:2009-3-20 15:39:27
string.Format("{0:m}",System.DateTime.Now) 结果为:3月20日
string.Format("{0:t}",System.DateTime.Now) 结果为:15:41
string.Format("{0:T}",System.DateTime.Now) 结果为:15:41:50
如果是直接使用Debug.log(string.Format("{0:f}"),显示出来的结果没有 日期,只有秒数的结果。
text_ui.text = "Time: " + string.Format("{0:f}", System.DateTime.Now);//using UnityEngine.UI;
如果是对UGUI的Text赋值,就会显示年月日,以及星期几。
参考文章:
1.
String.Format数字格式化输出 {0:N2} {0:D2} {0:C2
2.
Unity3d 之string 的格式化字符串
4.
5.
6.