[Unity]string.Format的用法

{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 的格式化字符串

3.

string.Format对C#字符串格式化

4.

5.

6.






  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值