您当前的位置: 首页 >  unity

CoderZ1010

暂无认证

  • 3浏览

    0关注

    168博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity 如何将秒数转化为00:00:00时间格式

CoderZ1010 发布时间:2021-10-10 13:24:21 ,浏览量:3

public static class FloatExtension
{
    /// 
    /// 将秒数转化为00:00:00格式
    /// 
    /// 秒数
    /// 00:00:00
    public static string ToTimeFormat(this float time)
    {
        //秒数取整
        int seconds = (int)time;
        //一小时为3600秒 秒数对3600取整即为小时
        int hour = seconds / 3600;
        //一分钟为60秒 秒数对3600取余再对60取整即为分钟
        int minute = seconds % 3600 / 60;
        //对3600取余再对60取余即为秒数
        seconds = seconds % 3600 % 60;
        //返回00:00:00时间格式
        return string.Format("{0:D2}:{1:D2}:{2:D2}", hour, minute, seconds);
    }
}
public class Foo : MonoBehaviour
{
    private void Start()
    {
        Debug.Log(300.38f.ToTimeFormat());
        Debug.Log(456.14f.ToTimeFormat());
        Debug.Log(48213.7f.ToTimeFormat());
    }
}

关注
打赏
1653184800
查看更多评论
立即登录/注册

微信扫码登录

0.0500s