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

时间:2021-02-05 10:42:54   收藏:0   阅读:0

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

技术图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!