using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Hotline.Share.Tools; public static class DoubleExtensions { /// /// 秒数转换成 x天x小时x分钟x秒 的字符串 /// /// /// public static string SecondsToString(this double value) { if (value <= 0) return string.Empty; var timeSpan = TimeSpan.FromSeconds(value); var days = timeSpan.Days; var hours = timeSpan.Hours; var minutes = timeSpan.Minutes; var seconds = timeSpan.Seconds; var sb = new StringBuilder(); if (days > 0) { sb.Append($"{days}天"); } if (hours > 0 || days > 0) { sb.Append($"{hours}小时"); } if (hours > 0 || days > 0 || minutes > 0) { sb.Append($"{minutes}分钟"); } sb.Append($"{seconds}秒"); return sb.ToString(); } public static string SecondsToString(this double? value) { if (value is null) return string.Empty; return value.Value.SecondsToString(); } }