C# 简单粗暴的毫秒转换成 分秒的格式

导读:本篇文章讲解 C# 简单粗暴的毫秒转换成 分秒的格式,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

C# 简单粗暴的毫秒转换成 分秒的格式

1:code(网络上很多存在拷贝或者存在bug的或者不满足自己的要求)

 1  public static string RevertToTime(double milliSeconds)//毫秒
 2         {
 3             double getsecond = milliSeconds * 1.0 / 1000;
 4             double getdoubleminuth = Math.Floor(getsecond / 60);
 5             string minuthTIme = string.Empty;
 6             string secondTime = string.Empty;
 7             string resultShow = string.Empty;
 8             if (getdoubleminuth >= 1)
 9             {
10                 minuthTIme = getdoubleminuth >= 10 ? $"{getdoubleminuth}" : $"0{getdoubleminuth}";
11                 double getmtemp = getdoubleminuth * 60;
12                 double getmtemp2 = getsecond - getmtemp;
13                 double timemiao = Math.Floor(getmtemp2);
14                 secondTime = $"{(timemiao >= 10 ? timemiao.ToString() : "0" + timemiao)}";
15                 resultShow = $"{minuthTIme}分{secondTime}秒";
16             }
17             else
18             {
19                 secondTime = getsecond >= 10 ? getsecond.ToString() : ("0" + getsecond);
20                 resultShow = $"0分{secondTime}秒";
21             }
22             return resultShow;
23 
24             #region old
25             //double getsecond = milliSeconds * 1.0 / 1000;//得到秒钟
26             //double getdoubleminuth = getsecond * 1.0 / 60;//得到分钟
27             //double scoreDes = Math.Round(getdoubleminuth, 0);
28             //return scoreDes > 0 ? $"{scoreDes}分0秒" : $"0分{Math.Round(getsecond, 0)}秒";
29             #endregion
30 
31         }

2:测试结果OK

C# 简单粗暴的毫秒转换成 分秒的格式

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/63974.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!