格式化毫秒数/毫秒转字符串
/// <summary> /// 格式化毫秒数 /// </summary> /// <param name="milliseconds"></param> /// <returns></returns> public static string FormatMilliseconds(long milliseconds) { try { List<Tuple<int, string>> lst = new List<Tuple<int, string>>() { new Tuple<int, string>(86400000,"天"), new Tuple<int, string>(3600000,"时"), new Tuple<int, string>(60000,"分"), new Tuple<int, string>(1000,"秒"), new Tuple<int, string>(1,"毫秒") }; StringBuilder str = new StringBuilder(); foreach (var item in lst) { if (milliseconds >= item.Item1) { var v = milliseconds / item.Item1; str.Append($"{v}{item.Item2}"); milliseconds -= v * item.Item1; } } return str.ToString(); } catch (Exception ex) { ErrorLog($"毫秒转换异常,{milliseconds},{ex.Message}{Environment.NewLine}{ex.StackTrace}"); return $"{milliseconds}毫秒"; } }