c# - 如何让Humanizer在精度更高的情况下不显示 "no time"?

标签 c# humanizer

我正在使用 Humanizer on a TimeSpan精度为 4:

(dateEnd - dateStart).Humanize(4)

它会生成这样的东西:

2 hours, 17 minutes, 20 seconds, 141 milliseconds

但是当剩余时间只有几分钟(还剩不到一个小时)时,它会生成:

17 minutes, 20 seconds, 141 milliseconds, no time

有没有办法不包括这个“没有时间”?

最佳答案

我这样做是为了根据运行时间长度更改精度:

TimeSpan runTime = dateEnd - dateStart;

if (runTime.TotalMinutes < 1)
{
    precision = 1; //49 seconds
}
else if (runTime.TotalHours < 1)
{
    precision = 2; //27 minutes, 49 seconds
}
else
{
    precision = 3; //1 day, 2 hours, 27 minutes  OR  2 hours, 27 minutes, 49 seconds
}

runTime.Humanize(precision);

关于c# - 如何让Humanizer在精度更高的情况下不显示 "no time"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24439474/

相关文章:

c# - 基于供应商 .NET 4.X 的应用程序无法生成 WSDL 客户端,因为 SSLv3 已禁用

c# - 断开连接后 TCP 客户端不重新连接

c# - WPF应用程序的手机/平板电脑风格密码框

c# - 使用 Html Helper 在页面末尾插入脚本

humanizer - 是否可以使用 Humanizer 将 TimeSpan 人性化为数年?

c# - DateTime 的人性化工具

c# - 为什么我不能使用 Humanizer 库中的 TextInfo.ToTitleCase 方法?

c# - 在每个/使用 Humanizer 或 Regex 周围添加空间

c# - UC 中的派生类给出 "type exist in both dlls"错误