在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
表示时间的数据格式为浮点数,如下:
需要将其格式化为{H:min:s.ms}格式的字符串,效果如下:
注: 博客主页: 实现/// <summary> /// 把浮点数格式化为{H:min:s.ms}格式的字符串 /// </summary> /// <param name="f">要格式化的浮点数</param> /// <returns>返回格式化后的字符串</returns> public static string FormatFloatToDateTimeString(double f) { string result = String.Empty; int day = (int)f / 3600 / 24; int hour = ((int)f / 3600 % 24); int min = ((int)f % 3600) / 60; int sec = (int)f % 60; int ms = (int)Math.Round((f - (int)f) * 1000, 0, MidpointRounding.AwayFromZero); if (day > 0) { result = String.Format("{0}.{1}:{2}:{3}.{4}", day, DataProcessor.FillZero(hour.ToString(), 2), DataProcessor.FillZero(min.ToString(), 2), DataProcessor.FillZero(sec.ToString(), 2), DataProcessor.FillZero(ms.ToString(), 3)); } else { result = String.Format("{0}:{1}:{2}.{3}", DataProcessor.FillZero(hour.ToString(), 2), DataProcessor.FillZero(min.ToString(), 2), DataProcessor.FillZero(sec.ToString(), 2), DataProcessor.FillZero(ms.ToString(), 3)); } return result; }
效果
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论