码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2021-02-05 10:42:54      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:mil   rev   lis   eve   图片   round   des   reg   简单   

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# 简单粗暴的毫秒转换成 分秒的格式

标签:mil   rev   lis   eve   图片   round   des   reg   简单   

原文地址:https://www.cnblogs.com/Fengge518/p/14374208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!