C# 简单粗暴的毫秒转换成 分秒的格式
2021-03-01 09:26
标签:mil rev lis eve 图片 round des reg 简单 C# 简单粗暴的毫秒转换成 分秒的格式 1:code(网络上很多都是错误的,或者存在bug,只好自己写一个了) 2:测试结果OK C# 简单粗暴的毫秒转换成 分秒的格式 标签:mil rev lis eve 图片 round des reg 简单 原文地址:https://www.cnblogs.com/Fengge518/p/14374208.html 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 }
文章标题:C# 简单粗暴的毫秒转换成 分秒的格式
文章链接:http://soscw.com/index.php/essay/58492.html